I have a pandas series with a multiindex like this:
my_series.head(5)
datetime_publication my_category
2015-03-31 xxx 24
yyy 2
zzz 1
qqq 1
aaa 2
dtype: int64
I am generating a horizontal bar chart using the plot
method from pandas
with all those stacked categorical values divided by datetime (according to the index hierarchy) like this:
my_series.unstack(level=1).plot.barh(
stacked=True,
figsize=(16,6),
colormap='Paired',
xlim=(0,10300),
rot=45
)
plt.legend(
bbox_to_anchor=(0., 1.02, 1., .102),
loc=3,
ncol=5,
mode="expand",
borderaxespad=0.
)
However I am not able to find a way to normalize all those values in the series broken down by datetime_publication,my_category
. I would like to have all the horizontal bars of the same length, but right now the legth depends on the absolute values in the series.
Is there a built-in functionality from pandas to normalize the slices of the series or some quick function to apply at the series that keeps track of the total taken from the multiindex combinatin of the levels?