Python:Matplotlib避免绘制间隙 [英] Python: Matplotlib avoid plotting gaps

查看:36
本文介绍了Python:Matplotlib避免绘制间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在生成以下情节:

I am currently generating the plot below:

使用以下代码:

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

其中 intra.to_pydatetime() 是:<<类'pandas.tseries.index.DatetimeIndex'>的绑定方法DatetimeIndex.to_pydatetime[2011-01-03 09:35:00,...,2011-01-07 16:00:00]长度:390,频率:无,时区:无>

所以日期从 2011-01-03 09:35:00 开始,增加 5 分钟直到 16:00:00,然后跳转到下一个天, 2011-01-04 09:35:00 直到 2011-01-04 16:00:00 ,依此类推.

So the dates go from 2011-01-03 09:35:00, increments by 5 minutes until 16:00:00, and then jumps to the next day, 2011-01-04 09:35:00 until 2011-01-04 16:00:00, and so on.

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

How can I avoid plotting the gaps between 16:00:00 and 9:30:00 on the following day? I don't want to see these straight lines.

更新:

我会尝试这个看看它是否有效.

I will try this to see if it works.

推荐答案

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

Simply set the two values defining the line you don't want to see as NaN (Not a Number). Matplotlib will hide the line between the two values automatically.

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

这篇关于Python:Matplotlib避免绘制间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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