[英]Plot stacked barplot with seaborn catplot
我想知道 plot 堆疊條 plot 是否可以與 seaborn 貓圖一起使用。 例如:
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')
我想堆疊kind
,但似乎 catplot 不采用 'stacked' 參數。
你不能使用sns.barplot
來做到這一點,我認為你能得到的最接近的是使用 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.