首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绘制堆叠条形图和seaborn catplot

绘制堆叠条形图和seaborn catplot
EN

Stack Overflow用户
提问于 2021-03-22 11:57:26
回答 1查看 1.7K关注 0票数 1

我想知道有没有可能将堆叠的条形图与海运猫图结合起来。例如:

代码语言:javascript
复制
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‘参数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-22 19:39:56

你不能使用sns.barplot来做到这一点,我认为你能得到的最接近的方法是使用sns.histplot:

代码语言:javascript
复制
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)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66740158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档