我有一个 DataFrame,由几个像这样的时间序列组成:
import pandas as pd
df = pd.DataFrame({'A': [10, 20, 30, 40],
'B': [15, 17, 16, 12],
'C': [33, 11, 49, 20]})
df
A B C
0 10 15 33
1 20 17 11
2 30 16 49
3 40 12 20
绘制一个简单的折线图就像一个魅力,即使是自动图例:
df.plot()
在文档中,如果找到描述为“如果为真,则创建堆积条形图。仅对 DataFrame 输入有效”stacked
的可选参数(布尔值,默认为 False)。所以我输入
df.plot(stacked=True)
并收到以下 TypeError 消息:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-110-8a5cc63390e6> in <module>()
----> 1 df.plot(stacked=True)
C:\Python27\lib\site-packages\pandas\tools\plotting.py in plot_frame(frame, x, y, subplots, sharex, sharey, use_index, f
igsize, grid, legend, rot, ax, style, title, xlim, ylim, logx, logy, xticks, yticks, kind, sort_columns, fontsize, secon
dary_y, **kwds)
1564 logy=logy, sort_columns=sort_columns,
1565 secondary_y=secondary_y, **kwds)
-> 1566 plot_obj.generate()
1567 plot_obj.draw()
1568 if subplots:
C:\Python27\lib\site-packages\pandas\tools\plotting.py in generate(self)
798 self._compute_plot_data()
799 self._setup_subplots()
--> 800 self._make_plot()
801 self._post_plot_logic()
802 self._adorn_subplots()
C:\Python27\lib\site-packages\pandas\tools\plotting.py in _make_plot(self)
1176
1177 try:
-> 1178 newline = plotf(*args, **kwds)[0]
1179 lines.append(newline)
1180 leg_label = label
C:\Python27\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs)
3994 lines = []
3995
-> 3996 for line in self._get_lines(*args, **kwargs):
3997 self.add_line(line)
3998 lines.append(line)
C:\Python27\lib\site-packages\matplotlib\axes.pyc in _grab_next_args(self, *args, **kwargs)
328 return
329 if len(remaining) <= 3:
--> 330 for seg in self._plot_args(remaining, kwargs):
331 yield seg
332 return
C:\Python27\lib\site-packages\matplotlib\axes.pyc in _plot_args(self, tup, kwargs)
316 ncx, ncy = x.shape[1], y.shape[1]
317 for j in xrange(max(ncx, ncy)):
--> 318 seg = func(x[:,j%ncx], y[:,j%ncy], kw, kwargs)
319 ret.append(seg)
320 return ret
C:\Python27\lib\site-packages\matplotlib\axes.pyc in _makeline(self, x, y, kw, kwargs)
266 **kw
267 )
--> 268 self.set_lineprops(seg, **kwargs)
269 return seg
270
C:\Python27\lib\site-packages\matplotlib\axes.pyc in set_lineprops(self, line, **kwargs)
207 funcName = "set_%s"%key
208 if not hasattr(line,funcName):
--> 209 raise TypeError('There is no line property "%s"'%key)
210 func = getattr(line,funcName)
211 func(val)
TypeError: There is no line property "stacked"
我是否以错误的方式调用该函数或者这是一个错误?