我有一个类似于下面由Seaborn docs生成的图:https://seaborn.pydata.org/generated/seaborn.violinplot.html

让我们不要在意这里的实际数据和标签,这只是为了演示。我想做的是从相同的数据(作为基线)创建所有的橙色分布。
因此,在这种情况下,所有的蓝色分布将针对每个工作日的相同橙色分布进行绘制。
这可以通过Seaborn中的内置功能来实现吗?
发布于 2019-09-30 22:10:24
我不认为有什么“内置的”东西可以做你想做的事情,但是如果你不介意对你的数据帧进行一点创造性的处理,这是相当容易的,但你必须提供你的数据帧的结构来确保。
以下是一种(非常低效)的方法来处理来自海运的tips数据集
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)

https://stackoverflow.com/questions/58164531
复制相似问题