如何禁用 plotly.express.line 中的趋势线? [英] How to disable trendline in plotly.express.line?

查看:19
本文介绍了如何禁用 plotly.express.line 中的趋势线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意在同一张图表上绘制 3 个时间序列.Datasource是一个pandas.DataFrame()对象,Timestamp的类型是datetime.date,3个不同的时间序列取自同一Value 列使用 plotly.express.line() 的颜色参数.

I am willing to plot 3 timeseries on the same chart. Datasource is a pandas.DataFrame() object, the type of Timestamp being datetime.date, and the 3 different time series drawn from the same column Value using the color argument of plotly.express.line().

图表上显示了 3 条线,但每条线都伴随着某种趋势线.我在函数签名中看不到如何禁用这些趋势线.你能帮忙吗?

The 3 lines show on the chart, but each one is accompanied by some sort of trendline. I can't see in the function signature how to disable those trendlines. Can you please help?

我已经做了几次尝试,例如使用另一个 color,但趋势线只是停留在那里.

I have made several attempts, e.g. using another color, but the trendlines just stay there.

请在下面找到代码片段和生成的图表.

Please find below the code snippet and the resulting chart.

import plotly.io as pio
import plotly.express as px
pio.renderers = 'jupyterlab'
fig = px.line(data_frame=df, x='Timestamp', y='Value', color='Position_Type')
fig.show()

(如果相关,我正在使用 jupyterlab)

(If relevant, I am using jupyterlab)

屏幕上的时间戳如下所示(这是 [常规] 每周时间序列):

Timestamp on the screen appears like this (this are [regular] weekly timeseries) :

并且,根据类型:

type(df.Timestamp[0])
> datetime.date

我要补充的是,我最初认为是趋势线的线看起来更像是从每个时间序列的第一个数据点到最后一个数据点的直线.

I am adding that it looks like the lines that I first thought were trendlines would rather be straight lines from the first datapoint to the last datapoint of each time series.

推荐答案

df_melt = df_melt.sort_values('datetime_id')

排序摆脱了那些环绕".感谢以上建议.使用 Plotly 4.8.2.

Sorting got rid of those "wrap-arounds". Thanks for the suggestions above. Using Plotly 4.8.2.

这篇关于如何禁用 plotly.express.line 中的趋势线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆