gpt4 book ai didi

python - Python 中 Plotly express 绘制的意外附加线

转载 作者:行者123 更新时间:2023-12-04 14:15:20 27 4
gpt4 key购买 nike

plotly_with_extra_diagonal_line

Plotly 从原始折线图的起点到终点绘制一条额外的对角线。

其他数据,其他图表工作正常。

只有此数据添加了该行。

为什么会发生这种情况?

我怎样才能解决这个问题?

下面是代码

temp = pd.DataFrame(df[{KEY_WORD}])
temp['date'] = temp.index
fig=px.line(temp.melt(id_vars="date"), x='date', y='value', color='variable')
fig.show()
plotly.offline.plot(fig,filename='Fig_en1')

最佳答案

刚刚遇到了同样的问题——尝试检查 X 轴上的重复值。我正在使用以下代码:

fig = px.line(df, x="weekofyear", y="interest", color="year")
fig.show()

这创造了以下 plotly :

plot with extra lines

我意识到这是因为在某些年份,我与前几年的周 52/53 相关的某些日期的周数因此创建了重复项,例如下面的索引 93 和 145:

date interest query year weekofyear
39 2015-12-20 44 home insurance 2015 51
40 2015-12-27 55 home insurance 2015 52
41 2016-01-03 69 home insurance 2016 53
92 2016-12-25 46 home insurance 2016 51
93 2017-01-01 64 home insurance 2017 52
144 2017-12-24 51 home insurance 2017 51
145 2017-12-31 79 home insurance 2017 52
196 2018-12-23 46 home insurance 2018 51
197 2018-12-30 64 home insurance 2018 52
248 2019-12-22 57 home insurance 2019 51
249 2019-12-29 73 home insurance 2019 52

通过修改这些(对于 1 月的日期较高的周数,我从年份列中减去 1)我似乎已经摆脱了这种现象:

plot with no extra lines

注意:由于数据集有点流动,图表之间可能存在一些其他差异。

关于python - Python 中 Plotly express 绘制的意外附加线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60799206/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com