我正在玩弄seaborn小提琴图,试图制作一个“小提琴”,并且每个小提琴都有不同的分布,以便于比较。
通过将x轴更改为x=smoker
,从here修改了简单示例,我得到了下图(如下所示)。
import seaborn as sns
sns.set(style="whitegrid", palette="pastel", color_codes=True)
# Load the example tips dataset
tips = sns.load_dataset("tips")
# Draw a nested violinplot and split the violins for easier comparison
sns.violinplot(x="smoker", y="total_bill", hue="smoker",
split=True, inner="quart", data=tips)
sns.despine(left=True)
我希望该图不会显示两个分开的一半,而只有一个小提琴具有两种不同的分布和颜色。
可以用seaborn做到这一点吗?也许还有其他图书馆?
谢谢!
答案 0 :(得分:1)
这是因为您要使用此行x="smoker"
为x轴指定两项。就是说,它描绘了吸烟者是和吸烟者是否。
您真正想做的是绘制所有数据。为此,您只需为x轴指定一个值即可。
sns.set(style="whitegrid", palette="pastel", color_codes=True)
# Load the example tips dataset
tips = sns.load_dataset("tips")
# Draw a nested violinplot and split the violins for easier comparison
sns.violinplot(x=['Data']*len(tips),y="total_bill", hue="smoker",
split=True, inner="quart",
palette={"Yes": "y", "No": "b"},
data=tips)
sns.despine(left=True)