python - Seaborn 小提琴情节 - 全部比较
问题描述
我有一个由 Seaborn 文档制作的如下图:https ://seaborn.pydata.org/generated/seaborn.violinplot.html
让我们不要介意这里的实际数据和标签,它只是为了演示。我想做的是从相同的数据(作为基线)创建所有橙色分布。
因此,在这种情况下,每个工作日的所有蓝色分布都将针对相同的橙色分布进行绘制。
Seaborn 的内置功能可以做到这一点吗?
解决方案
我不认为有任何“内置”可以做你想做的事,但如果你不介意对你的数据框有一点创意,这很容易做到,但你必须提供你的结构数据框以确保。
这是使用tips
seaborn 的数据集的一种(非常低效的)方法
target_var = 'total_bill'
hue_var = 'smoker'
hue_value = 'Yes'
cat_var = 'day'
grouped_value = 'ALL WEEK'
tips = sns.load_dataset("tips")
tips2 = tips.loc[tips[hue_var]==hue_value]
for cat in tips[cat_var].unique():
temp = tips.loc[:,[target_var]]
temp[cat_var] = cat
temp[hue_var] = grouped_value
tips2 = tips2.append(temp, ignore_index=True, sort=False)
fig, (ax1, ax2) = plt.subplots(1,2, figsize=(10,4))
sns.violinplot(x=cat_var, y=target_var, hue=hue_var, hue_order=['Yes','No'],
order=['Thur','Fri','Sat','Sun'],
data=tips, palette="muted", split=True, ax=ax1)
sns.violinplot(x=cat_var, y=target_var, hue=hue_var, hue_order=[hue_value,grouped_value],
order=['Thur','Fri','Sat','Sun'],
data=tips2, palette="muted", split=True, ax=ax2)
推荐阅读
- yii2 - 我无法从我的 yii 框架后端访问 Gii 界面
- swiftui - 有没有办法在针对 iOS 13 时有条件地使用 @StateObject?
- javascript - 赛普拉斯测试自动化中的 CORS 问题。"chromeWebSecuirty": false 在 Chrome 最新版本中不起作用
- javascript - 如何从 woocommerce 订单中删除“价格后缀”
- .net - 2020 年 7 月更新后的 SQL CLR 错误
- python-3.x - 将数字转换为日期时间格式
- python - 将属性传递给类方法
- velo - 如何访问 Wix 数据库中的类别
- tcl - 如何将字符串连接到列表元素的末尾?
- python - 如何在 Python 中访问多个打开的 Excel 文件