带有时间的矩形图作为x轴python pylab

时间:2018-07-24 12:02:27

标签: python python-3.x matplotlib plotly

我已经尝试过并得到错误:

pylab.Rectangle(height=2,width=1,xy=(df.index,df.Forecast))

错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-539-f66a97b6403e> in <module>()
----> 1 pylab.Rectangle(height=2,width=1,xy=(df.index,df.color))

c:\python35\lib\site-packages\matplotlib\patches.py in __init__(self, xy, width, height, angle, **kwargs)
    692         self._height = height
    693 
--> 694         self._x1 = self._x0 + self._width
    695         self._y1 = self._y0 + self._height
    696 

c:\python35\lib\site-packages\pandas\core\indexes\datetimelike.py in __add__(self, other)
    652                 return self._add_delta(other)
    653             elif is_integer(other):
--> 654                 return self.shift(other)
    655             elif isinstance(other, (Index, datetime, np.datetime64)):
    656                 return self._add_datelike(other)

c:\python35\lib\site-packages\pandas\core\indexes\datetimelike.py in shift(self, n, freq)
    780 
    781         if self.freq is None:
--> 782             raise ValueError("Cannot shift with no freq")
    783 
    784         start = self[0] + n * self.freq

ValueError: Cannot shift with no freq

数据集的样本如下所示:

                    Forecast    color
Time                                                                
2018-07-24 03:50:00 1.168318    r
2018-07-24 03:49:00 1.168393    r
2018-07-24 03:48:00 1.168798    r
2018-07-24 03:47:00 1.169103    g
2018-07-24 03:46:00 1.168032    r

我想用数据框的color栏中提到的颜色显示矩形。

即使有时我想在同一时间绘制一个不同的值时,有时也会出现。请告诉我如何实现我的想法

0 个答案:

没有答案