簡體   English   中英

Plot 堆疊條形圖與 seaborn 貓圖

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM