Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack a bar chart for a single series pandas

I know how to create a stacked bar chart using a dataframe with multiple rows, but is there a way to plot a series such that each index in the series in put into a stacked bar plot?

What I get is something like this:

dodged bar graph

Code:

series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
series.plot(kind = 'bar')

But what I want is to show a,b,c, and d all in one stacked bar graph. Can somebody help?

like image 258
Dave Avatar asked Dec 13 '22 21:12

Dave


1 Answers

Not sure what you want since you haven't specified the desired output, but here is a try

pd.DataFrame(series).T.plot.bar(stacked=True)

enter image description here

like image 73
tarashypka Avatar answered Dec 16 '22 11:12

tarashypka