I am trying to create a stacked barplot in seaborn with my dataframe.
I have first generated a crosstab table in pandas like so:
pd.crosstab(df['Period'], df['Mark'])
which returns:
Mark False True
Period BASELINE 583 132
WEEK 12 721 0
WEEK 24 589 132
WEEK 4 721 0
I would like to use seaborn to create a stacked barplot for congruence, ans this is what I have used for the rest of my graphs. I have struggled to do this however as I am unable to index the crosstab.
I have been able to make the plot I want in pandas using .plot.barh(stacked=True)
but no luck with seaborn. Any ideas how i can do this?
Thanks
The guy who created Seaborn doesn't like stacked bar charts (but that link has a hack which uses Seaborn + Matplotlib to make them anyway).
If you're willing to accept a grouped bar chart instead of a stacked one, here's one approach:
As you said you can use pandas to create the stacked bar plot. The argument that you want to have a "seaborn plot" is irrelevant, since every seaborn plot and every pandas plot are in the end simply matplotlib objects, as the plotting tools of both libraries are merely matplotlib wrappers.
So here is a complete solution (taking the datacreation from @andrew_reece's answer).