栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用sharex = True在catplot(kind ='violin')的顶部对seaborn catplot(kind='count')进行子图绘制

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用sharex = True在catplot(kind ='violin')的顶部对seaborn catplot(kind='count')进行子图绘制

通常,不可能将几个Seaborn图形级功能的输出组合到一个图形中。参见(此问题,也此问题)。我曾经写过一篇hack文章,从外部将这些数字组合起来,但是它有几个缺点。如果适合您,请随意使用它。

但通常,请考虑手动创建所需的图。在这种情况下,它可能看起来像这样:

import seaborn as snsimport matplotlib.pyplot as pltsns.set()fig, axes = plt.subplots(2,2, figsize=(8,6), sharey="row", sharex="col")tips = sns.load_dataset("tips")order = tips["sex"].unique()hue_order = tips["smoker"].unique()for i, (n, grp) in enumerate(tips.groupby("time")):    sns.countplot(x="sex", hue="smoker", data=grp,        order=order, hue_order=hue_order, ax=axes[0,i])    sns.violinplot(x='sex', y='total_bill', hue='smoker', data=grp,        order=order, hue_order=hue_order,        split='True', cut=0, bw=0.25,         scale='area', scale_hue=False,  inner='quartile',         ax=axes[1,i])    axes[0,i].set_title(f"time = {n}")axes[0,0].get_legend().remove()axes[1,0].get_legend().remove()axes[1,1].get_legend().remove()plt.show()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624948.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号