我认为没有任何“内置”功能可以满足您的需求,但如果您不介意对数据框进行一些创意,这很容易做到,但您必须提供确保数据框的结构。
这是使用 seaborn 的 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)