简体   繁体   English

如何在matplotlib.pyplot.plot中删除连接不连续点的线

[英]how to remove line connecting discontinued point in matplotlib.pyplot.plot

I have a dataframe which has one column shows price, and its index is datetime. 我有一个数据框,其中有一栏显示价格,它的索引是日期时间。

2018-09-18T02:29:56.5   524.6
2018-09-18T02:29:57.0   524.6
2018-09-18T02:29:57.5   524.8
2018-09-18T02:29:59.0   525.1
2018-09-18T02:29:59.5   525.1
2018-09-18T02:30:00.0   524.8
2018-09-19T21:00:00.5   527.1
2018-09-19T21:00:01.0   527.1
2018-09-19T21:00:01.5   527.3
2018-09-19T21:00:02.0   527.7
2018-09-19T21:00:02.5   527.5
2018-09-19T21:00:03.0   527.6
2018-09-19T21:00:03.5   527.4

im trying to plot the timeplot by matplotlib.pyplot.plot(df) . 我试图通过matplotlib.pyplot.plot(df)绘制时间图。 It gives a plot but with a long straight line connecting the discontinued datapoint (last data point on 2018-09-18T02:30:00.0 and the first data point on 2018-09-19T21:00:00.5). 它给出了一个图,但是有一条长直线连接不连续的数据点(2018-09-18T02:30:00.0的最后一个数据点和2018-09-19T21:00:00.5的第一个数据点)。 Is there a way to remove the connecting line between the data point gap? 有没有办法消除数据点间隙之间的连接线?

sry... i think how i can do it... just use 对不起...我想我该怎么做...就用

df.plot(x=df.index.astype(str))

basically, convert my index from datetime to string, and use the strings as my x-axis 基本上,将我的索引从日期时间转换为字符串,然后将字符串用作我的x轴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM