Tiger1982
Tiger1982

Reputation: 19

Plotly, show only trendline and no data

I have a dataframe with two columns and several thousand rows. I am plotting this in python by using plotly (px.scatter) and I created a trendline with rolling average 20.

fig = px.scatter(df3, x='Index', y='Average Amplitude (dB)', hover_data=['Average Amplitude (dB)'],
             color='Average Amplitude (dB)', trendline="rolling", trendline_options=dict(window=20),
             trendline_color_override="black", title='Average Amplitude (dB)')

I there a way to make the plotly graph just showing the trendline and not all the other values? I just want to see the average of 20 data points and not the raw values.

Thanks.

Upvotes: 0

Views: 1096

Answers (1)

r-beginners
r-beginners

Reputation: 35205

A scatterplot with trendlines consists of two graphical elements: a scatterplot and a line chart. So, after creating the graph, delete the first scatter plot. Since it is in tuple format, we use slices to keep only the trendlines. I have modified the code to what you expect based on the example in the reference since you did not present any data.

import plotly.express as px

df = px.data.stocks(datetimes=True)
fig = px.scatter(df,
                 x="date",
                 y="GOOG",
                 trendline="rolling",
                 trendline_options=dict(window=5),
                title="5-point moving average"
                )
fig.data = fig.data[1:]
fig.show()

enter image description here

Graph before deletion enter image description here

Upvotes: 2

Related Questions