I have recently implemented a LOWESS trendline using Plotly express when I noticed it didn’t look quite right.
Replicating the example from the docs does not appear to produce the trendline as shown in the screenshot.
If we do this manually using LOWESS directly from statsmodels and then plotting it using Plotly we get the trendline that matches the screenshot in the docs. Green is the manually produced trendline. Blue is the Plotly express LOWESS trend line. They both use a fraction of 0.1.
import plotly.express as px import plotly.graph_objects as go import pandas as pd import numpy as np import statsmodels.api as sm df = px.data.stocks(datetimes=True) lowess = sm.nonparametric.lowess z = lowess(df['GOOG'],df['date'],frac=0.1) fig = px.scatter(df, x="date", y="GOOG", trendline="lowess", trendline_options=dict(frac=0.1)) fig.add_trace(go.Scatter( x=pd.to_datetime(z[:,0],unit='ns'), y=z[:,1], mode='lines', name='manual' )) fig.show()
Any idea what’s going on here or if I am doing something wrong?