3

I have a DataFrame, consisting of several timeseries like this:

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

Plotting a simple line diagram works like a charm, even with automatic legend:

df.plot()

In the documentation, if find the optional parameter stacked (boolean, default False) with the description "If True, create stacked bar plot. Only valid for DataFrame input". So I type

df.plot(stacked=True)

and receive the following TypeError message:

---------------------------------------------------------------------------
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"

Did I call the function in a wrong way or is this a bug?

1 Answer 1

2
df.plot(kind='barh', stacked=True)
Sign up to request clarification or add additional context in comments.

1 Comment

Argh, the part "... creates stacked bar plot..." should have given it away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.