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")
|
||||
Reference in New Issue
Block a user