首页 > 解决方案 > 拆分 Seaborn 小提琴图表中的控制边

问题描述

有(如示例:https ://seaborn.pydata.org/examples/grouped_violinplots.html )

sns.set(style="whitegrid", palette="pastel", color_codes=True)

# Load the example tips dataset
tips = sns.load_dataset("tips")
tips = tips[(tips['day'] == 'Sun')]
# Draw a nested violinplot and split the violins for easier comparison
sns.violinplot(x="day", y="total_bill", hue="smoker",
           split=True, inner="quart",
           palette={"Yes": "y", "No": "b"},
           data=tips)
sns.despine(left=True)

你得到:

在此处输入图像描述

是否可以控制两侧,即:指定“否”左和“是”右?

我遇到的问题是,在生成多个图时,我得到的图像在不同的侧面都有数据,例如:

在此处输入图像描述

在此处输入图像描述

我想在所有图像上都有“下降”,“上升”。

谢谢!

标签: pythonseaborn

解决方案


是的,有可能,来自官方文档

order, hue_order : 字符串列表,可选
绘制分类级别的顺序,否则从数据对象中推断级别。

sns.violinplot(x="day", y="total_bill", hue="smoker",hue_order=['No','Yes'],
       split=True, inner="quart",
       palette={"Yes": "y", "No": "b"},
       data=tips)  

在此处输入图像描述


推荐阅读