I would like to know if someone knows of an easy way to make an OLS trendline in ploty express pass through the origin. I have been looking for quite some time now so it would be much appreciated.
Asked
Active
Viewed 500 times
0
-
You can remove the constant from the regression formula, so that it looks like `y = a * x`, which passes through the origin, because `a * 0 = 0` – ForceBru Sep 17 '21 at 12:21
-
you would most likely get more responses if you can add a screenshot of what your expected output is. – Gangula Sep 24 '21 at 19:23
1 Answers
3
With plotly.express.scatter(), there is a trendline_options variable passed in as a dictionary. Set the add_constant key to False; i.e.
fig = px.scatter(df, x=x, y=y, trendline="ols", trendline_options={"add_constant": False})

neelsnarayan
- 31
- 3