Line on plot is too smoothed

I am redoing a graph that I previously had with another package. The line is very smooth compared to the values. How do I change the code to have the line not smoothed out, or finer grained ?

Old graph (Knowm XChart) as example:

plotly-express graph:

My code:

fig = px.line(df, x='date', y='value', title="Rand/Bitcoin", width=1360, height=387, template="plotly_dark")#, line_shape="linear")
fig.update_traces(line_color='Chocolate')
fig.update_xaxes(tickfont=dict(size=8, color="DarkGrey"), title="Date", titlefont=dict(size=8, color="DarkGrey"))
fig.update_yaxes(tickfont=dict(size=8, color="Chocolate"), title="Rand", titlefont=dict(size=8, color="Chocolate")

Hey @ou_ryperd , welcome to the community.

There is no such thing as smoothing in plotly.

Maybe it looks like this due to different axis ranges. What does your plot like if you adjust the ranges to correspond to the first graph?

1 Like

Thank you for your answer.
I thought the same. I have tried all of the following separately but none of them changes the y axis lables to be in even multiples.

fig.update_layout(layout_yaxis_range=[800000.00,1400000.00])
fig.update_yaxes(tickvals = [800000,900000,1000000,1100000,1200000,1300000],
                               ticktext=['{:.2}M'.format(x / 1000000) for x in df['value']],
                               ticktext = ['800000','900000','1000000','1100000','1200000','1300000'],
                               tick0 = 800000, dtick = 200000
)

Tickvals and ticktext changes the yaxis labels but then the line is gone:

It looks to me like it’s not that the second graph is smoothed, but that the second graph is showing a cumulative sum of the data in the first graph.

Here is how I source the data:

df = pd.read_sql_query("SELECT date, btc as value from coins where btc is not null order by date asc;", conn)
df['date'] = pd.to_datetime(df['date'])

The line does look cumulative, but then the top value would be much higher. The value is around 1.2 mil Rand each at the moment.

In the original pair of graphs you posted images for, the top value in the second graph is around 125 million, or am I misreading that?

1 Like

Correct. I see now that my data is dirty. Thank you for your keen eye.

After cleaning up my data (in a previous cleanup n.00 was converted to n00.00 by mistake in some cases) the line was still the same shape. I finally fixed it with:

df['value'] = pd.to_numeric(df['value'])

And now it is exactly how I wanted. Thank you all.

1 Like