Python 时间为x轴的矩形图形
我已尝试此操作,但出现错误:Python 时间为x轴的矩形图形,python,python-3.x,matplotlib,plotly,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-
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
我想用dataframe的color
列中提到的颜色显示矩形
甚至有时我想在同一时间绘制不同的值,一个高于另一个。请告诉我如何才能实现我的想法现在还不太清楚你想实现什么。矩形由空间中的点(x,y)以及宽度和高度定义。此外,您还可以指定一种面部颜色或边缘颜色。尊敬的先生@ImportanceOfBeingErnest我已经尝试过类似的方法。正如您在代码中看到的,我也指定了高度、宽度和xy坐标。但是我得到了以下错误。请看一看,并建议我,如果你有什么不同于我尝试的,或者如果有任何需要改进的地方。点(x,y)需要定义为元组或两个数字的列表,例如(2,3)。在这里,您尝试使用类似于
(pandas.Series,pandas.Series)
,这不是重点。还有一点不能是(2,“r”),这就是为什么我真的不知道你在努力实现什么。@ImportanceOfBeingErnest请原谅我。我在y
轴中尝试了df.Forecast
。我想要得到相应矩形的color
列中的颜色。我想我明白了。如果还有什么需要知道的,请告诉我。Forecast是一个有很多值的列。对于一个矩形,您需要一个点,而不是多个点。
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