Trendline for subplots

Hi there,

I know adding OLD trendline should be very easy, i did this many times but somehow I cant do it in the code below. I looked so many pages but still no lack. Could anyone point me in the right direction please?

fig= make_subplots(rows=2, cols=3, subplot_titles=(’’))

fig.add_trace(go.Scatter(x=dfsg[‘GBP/Loc’], y=dfsg[‘Vol’],opacity=0.55,mode=‘markers’), row=1, col=1)
fig.add_trace(go.Scatter(x=dfau[‘GBP/Loc’], y=dfau[‘Vol’],opacity=0.55,mode=‘markers’), row=1, col=2)
fig.add_trace(go.Scatter(x=dfcn[‘GBP/Loc’], y=dfcn[‘Vol’],opacity=0.55,mode=‘markers’), row=1, col=3)
fig.add_trace(go.Scatter(x=dfhk[‘GBP/Loc’], y=dfhk[‘Vol’],opacity=0.55,mode=‘markers’), row=2, col=1)
fig.add_trace(go.Scatter(x=dfjp[‘GBP/Loc’], y=dfjp[‘Vol’],opacity=0.55,mode=‘markers’), row=2, col=2)
fig.add_trace(go.Scatter(x=dfkr[‘GBP/Loc’], y=dfkr[‘Vol’],opacity=0.55,mode=‘markers’), row=2, col=3)

fig.update_layout(height=500, width=800,
title_text=“Multiple Subplots with Titles”)

fig.show()

If you switch to using plotly.express you can use trendline="ols" but you’ll need to merge your dataframes into one and use facet_col and facet_col_wrap

Hey Nicolas, thank you for the advise. I tried before to do what you suggested, the trend line was perfect but the thing is I wanted the axes to be different in the charts otherwise in some of them all dots will be squished.

Do you think is that possible with the approach you suggested?

Yep, check out the facet docs here for independent axes using matches=None: https://plotly.com/python/facet-plots/#facets-with-independent-axes