I’ve set the ‘add_constant’ parameter of the OLS trendline to false, so that the trendline starts from the origin. Additionally, I’ve defined the range of x and y values to start from the origin. However, despite these settings, the trendline does not start from the origin as expected. Is there a solution to ensure that the trendline starts from the origin as intended?
import plotly.express as px
import pandas as pd
# Sample data
df = pd.DataFrame({
'x': [10, 12, 13, 14, 15],
'y': [12, 13, 14, 15, 16]
})
# Create scatter plot with trendline
fig = px.scatter(df, x='x', y='y', trendline="ols", trendline_options=dict(add_constant=False))
# Set x and y axis range to start from the origin
fig.update_layout(xaxis=dict(range=[0, 16]), yaxis=dict(range=[0, 17]))
fig.show()