How to disable trendline in plotly.express.line?(如何禁用 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 中的趋势线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何禁用 plotly.express.line 中的趋势线?
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
