Reputation: 1694
I wonder is it possible to plot stacked bar plot with seaborn catplot. For example:
import seaborn as sns
exercise = sns.load_dataset("exercise")
plot = exercise.groupby(['diet'])['kind'].value_counts(normalize=True).mul(100).reset_index(name='percentage%')
g = sns.catplot(x="diet", y="percentage%", hue="kind", data=plot, kind='bar')
I'd like to stack kind
, but it seems catplot doesn't take 'stacked' parameter.
Upvotes: 4
Views: 7935
Reputation: 46888
You cannot do it using sns.barplot
, i think the closest you can get is using sns.histplot:
import seaborn as sns
exercise = sns.load_dataset("exercise")
plot = exercise.groupby(['diet'])['kind'].value_counts(normalize=True).mul(100).reset_index(name='percentage')
g = sns.histplot(x = 'diet' , hue = 'kind',weights= 'percentage',
multiple = 'stack',data=plot,shrink = 0.7)
Upvotes: 3