My goal is to create a stacked bar chart of a multilevel dataframe. The dataframe looks like this:
import pandas as pd
import numpy as np
arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux', 'qux']),
np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two', 'three'])]
s = pd.Series([10,20,10,22,10,24,10,26, 11], index=arrays)
In[1]: s
Out[1]:
bar one 10
two 20
baz one 10
two 22
foo one 10
two 24
qux one 10
two 26
three 11
dtype: int64
I have two goals:
create a stacked bar chart such that the values are stacked to 4 single bins called
bar
,baz
,foo
,qux
.the 4 bars should be ordered by size. In this example, the
qux
bar will have height (10+26+11=)47 and should be the first left, followed by thefoo
bar which has height (10+24)=34.