Plotly express scatter trendline not showing trendline for subplots

Hi,

Iโ€™m using plotly express scatter plot with trendline and facet, however I observe some subplots the trendline is not shown. Any reason why this is happening? Thanks!

fig = px.scatter(df, x="A", y="B",facet_col="C",
            trendline="ols",template="simple_white")

The 1st and 3rd subplots show no trendline at all. Thank you so much! I really appreciate any suggestions.

1 Like

Thatโ€™s very strangeโ€ฆ are you able to share a sample dataset for which this is happening please?

Getting the same thing.

Hereโ€™s some of my code

fig1 = px.scatter(cases, x="date_new", y="positive_pct_change", trendline="lowess", title="positive_pct_change")
fig1.update_layout(
    height=400)
fig1.show()

fig2 = px.scatter(cases, x="date_new", y="negative_pct_change", trendline="lowess", title="negative_pct_change")
fig2.update_layout(
    height=400)
fig2.show()

fig3 = px.scatter(cases, x="date_new", y="death_pct_change", trendline="lowess", title="death_pct_change")
fig3.update_layout(
    height=400)
fig3.show()

fig4 = px.scatter(cases, x="date_new", y="hospitalized_pct_change", trendline="lowess", title="hospitalized_pct_change")
fig4.update_layout(
    height=400)
fig4.show()

fig5 = px.scatter(cases, x="date_new", y="total_cases_pct_change", trendline="lowess", title="total_cases_pct_change")
fig5.update_layout(
    height=400)
fig5.show()

#add traces
trace1 = fig1['data'][0]
trace2 = fig2['data'][0]
trace3 = fig3['data'][0]
trace4 = fig4['data'][0]
trace5 = fig5['data'][0]

fig = make_subplots(rows=3
                    ,cols=2
                    ,shared_xaxes=False
                    ,row_heights=[9., 9., 9.]
                    ,column_widths=[.1, .1]
                    ,shared_yaxes=False
                    ,vertical_spacing=0.05
                   )

fig.add_trace(trace1, row=1, col=1)
fig.add_trace(trace2, row=1, col=2)
fig.add_trace(trace3, row=2, col=1)
fig.add_trace(trace4, row=2, col=2)
fig.add_trace(trace5, row=3, col=1)

fig['layout'].update(height=1000, width=1000, title='Stacked Subplots with Non-Shared X-Axes')

print(fig.layout)

fig.show()

df looks like this:

	date_new	totalTestResultsIncrease	negativeIncrease	positiveIncrease	deathIncrease	hospitalizedIncrease
0	2020-07-16 00:00:00	830918	759689	71229	977	2251
1	2020-07-15 00:00:00	756470	691364	65106	855	2380
2	2020-07-14 00:00:00	760282	697403	62879	736	2262
3	2020-07-13 00:00:00	722099	663634	58465	327	1214
4	2020-07-12 00:00:00	727318	666340	60978	476	939
5	2020-07-11 00:00:00	635437	572430	63007	757	5141
6	2020-07-10 00:00:00	823375	756730	66645	854	2318
7	2020-07-09 00:00:00	700380	641544	58836	867	1719
8	2020-07-08 00:00:00	626670	564523	62147	897	2035
9	2020-07-07 00:00:00	633221	581455	51766	922	1960

trendlines work fine when not in a subplot it seems. Also, the title and axes names doesnโ€™t show up in the subplots either.

I was facing the same issue, but for me it was the NaN values in the data, I just used df.dropna() method and trendline showed.
Hope it helps