gpt4 book ai didi

Python:Matplotlib 避免绘制间隙

转载 作者:行者123 更新时间:2023-12-05 01:01:58 25 4
gpt4 key购买 nike

我目前正在生成下面的图:
plot

使用此代码:

ax = plt.subplots()
ax.plot(intra.to_pydatetime(), data)
plt.title('Intraday Net Spillover')
fig.autofmt_xdate()

哪里 intra.to_pydatetime()是: <bound method DatetimeIndex.to_pydatetime of <class 'pandas.tseries.index.DatetimeIndex'>
[2011-01-03 09:35:00, ..., 2011-01-07 16:00:00]
Length: 390, Freq: None, Timezone: None>

所以日期来自 2011-01-03 09:35:00 , 增加 5 分钟直到 16:00:00 ,然后跳转到第二天, 2011-01-04 09:35:00直到 2011-01-04 16:00:00 , 等等。

如何避免在第二天绘制 16:00:00 和 9:30:00 之间的差距?我不想看到这些直线。

更新:

我会试试 this看看它是否有效。

最佳答案

只需将定义您不想看到的行的两个值设置为 NaN(非数字)。 Matplotlib 将自动隐藏两个值之间的线。

看看这个例子:
http://matplotlib.org/examples/pylab_examples/nan_test.html

关于Python:Matplotlib 避免绘制间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27266987/

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