2025.46 changes
This commit is contained in:
30
source/plotting/charts/plotly_regression_curve.py
Normal file
30
source/plotting/charts/plotly_regression_curve.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from plotly.graph_objs import Figure, Scatter
|
||||
from scipy.ndimage import gaussian_filter
|
||||
|
||||
# Créer une courbe aléatoire lissée de valeurs entre 1 et 80
|
||||
SIZE: int = 500
|
||||
np.random.seed(4) # Pour reproduire les résultats
|
||||
df = pd.DataFrame(data={"col1": gaussian_filter(np.random.random(size=SIZE) * 79.0 + 1.0, sigma=SIZE / 133)})
|
||||
# Calculer les coefficients d'une régression de degré 2 pour col1
|
||||
c2, c1, c0 = np.polyfit(df.index, df["col1"], 2)
|
||||
df["reg1"] = c2 * df.index**2 + c1 * df.index + c0
|
||||
|
||||
# Créer une image avec deux lignes
|
||||
figure = Figure(
|
||||
data=[
|
||||
Scatter(name="values", x=df.index, y=df["col1"], line={"color": "gray", "width": 1}, mode="lines"),
|
||||
Scatter(
|
||||
name="regression", x=df.index, y=df["reg1"], line={"color": "red", "width": 4, "dash": "dot"}, mode="lines"
|
||||
),
|
||||
],
|
||||
layout={
|
||||
"template": "seaborn",
|
||||
"xaxis1": {"title": "time"},
|
||||
"title": "Test de régression",
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"yaxis1": {"title": "value"},
|
||||
},
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||
@@ -6,14 +6,12 @@ from plotly.graph_objs import Figure, Bar
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600]
|
||||
"weight": [400, 500, 100, 250, 150, 350]
|
||||
})
|
||||
figure: Figure = make_subplots(rows=1, cols=3, subplot_titles=("Prix", "Poids unitaires"))
|
||||
subplot = figure.get_subplot(row=1, col=2)
|
||||
subplot.xaxis["domain"] = [0.3555555, 1.0]
|
||||
print(subplot, dir(subplot))
|
||||
figure: Figure = make_subplots(rows=1, cols=2, subplot_titles=("Prix", "Poids unitaires"))
|
||||
# subplot = figure.get_subplot(row=1, col=2)
|
||||
# subplot.xaxis["domain"] = [0.3555555, 1.0]
|
||||
figure.add_trace(Bar(name="Prix", x=data["product"], y=data["price"]), row=1, col=1)
|
||||
figure.add_trace(Bar(name="Poids", x=data["product"], y=data["weight"]), row=1, col=2)
|
||||
figure.update_layout(template="seaborn", title="Prix et poids unitaires", font={"family": "Cabin", "size": 13})
|
||||
figure.update_traces(row=1, col=2, specs=2)
|
||||
figure.show(renderer="browser")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar, Scatter
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(
|
||||
data={
|
||||
@@ -8,13 +8,21 @@ data = pd.DataFrame(
|
||||
"weight": [250, 300, 200, 400, 500, 600],
|
||||
}
|
||||
)
|
||||
figure: Figure = Figure(data=[Bar(name="Prix", x=data["product"], y=data["price"])])
|
||||
figure.add_hrect(y0=2.75, y1=4.5, fillcolor="gray", opacity=0.25, layer="below")
|
||||
figure: Figure = Figure(data=[])
|
||||
figure.add_hrect(
|
||||
y0=2.75,
|
||||
y1=4.5,
|
||||
fillcolor="gray",
|
||||
opacity=0.25,
|
||||
layer="below",
|
||||
)
|
||||
figure.add_trace(Bar(name="Prix", x=data["product"], y=data["price"]))
|
||||
figure.add_annotation(text="Zone de prix spéciale", xref="paper", yref="paper", x=0.5, y=0.5, xanchor="center", yanchor="middle", showarrow=False, font={"family": "Cabin", "size": 20})
|
||||
figure.update_layout(
|
||||
template="seaborn",
|
||||
title="Prix et poids unitaires",
|
||||
font={"family": "Cabin", "size": 13},
|
||||
xaxis={"title": "Produit", "showgrid": False},
|
||||
yaxis={"title": "Prix (€)", "showgrid": False}
|
||||
yaxis={"title": "Prix (€)", "showgrid": False},
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||
|
||||
Reference in New Issue
Block a user