Seaborn 中 violinplot 的边缘颜色不是由色调决定的
Edgecolor of violinplot in Seaborn is not determined by the hue
我创建了一个与 Seaborn 画廊中的小提琴图非常相似的图:
import seaborn as sns
sns.set(style="whitegrid", palette="pastel", color_codes=True)
tips = sns.load_dataset("tips")
sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
inner="quart", palette={"Male": "b", "Female": "y"})
sns.despine(left=True)
但是,我无法通过色调改变边缘颜色(上例中的 "Male" 和 "Female")。 Stack Exchange 上的先前答案在 Seaborn 条带图的上下文中解决了这个问题,但 violinplot 的几何形状似乎需要不同的解决方案。
我认为这就是 seaborn 的 violinplot 目前的工作方式。在源代码中(site-packages/seaborn/distributions.py
,在violinplot()
:
for side in [-1, 1]:
ax_plot((side * dens) + x, y, c=gray, lw=lw)
所以:
当您在系统上找到它时,您可以对其进行编辑。
文档字符串明确指出颜色参数是针对小提琴内部的:
color : mpl color, sequence of colors, or seaborn palette name
Inner violin colors
我创建了一个与 Seaborn 画廊中的小提琴图非常相似的图:
import seaborn as sns
sns.set(style="whitegrid", palette="pastel", color_codes=True)
tips = sns.load_dataset("tips")
sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
inner="quart", palette={"Male": "b", "Female": "y"})
sns.despine(left=True)
但是,我无法通过色调改变边缘颜色(上例中的 "Male" 和 "Female")。 Stack Exchange 上的先前答案在 Seaborn 条带图的上下文中解决了这个问题,但 violinplot 的几何形状似乎需要不同的解决方案。
我认为这就是 seaborn 的 violinplot 目前的工作方式。在源代码中(site-packages/seaborn/distributions.py
,在violinplot()
:
for side in [-1, 1]:
ax_plot((side * dens) + x, y, c=gray, lw=lw)
所以:
当您在系统上找到它时,您可以对其进行编辑。
文档字符串明确指出颜色参数是针对小提琴内部的:
color : mpl color, sequence of colors, or seaborn palette name Inner violin colors