如何更改seaborn displot的颜色饱和度?

时间:2021-05-08 02:55:07

标签: python-3.x seaborn

我已经安装了最新版本的 seaborn (0.11.1)。当我使用自定义颜色绘制历史记录时,它显示的颜色与我预期的不同(请参阅 sns.palplot 的颜色)。对于一些api,它有一个saturation参数,但对于displot没有。

dat_plots_mod = dat_plots.copy(deep=True)
dat_plots_mod.loc[dat_plots_mod.LDS == "FC", "LDS"] = "F"
palette = ["#9b59b6", "#ff0000", "#00f0f0", "#00ff00", "#000000", "#320ff0"]
sns.set_theme(style="ticks", font_scale=1.3)
g = sns.displot(
    x="AgeRS", 
    hue="LDS", 
    data=dat_plots_mod, 
    palette=palette, 
    aspect=1.5,
)
g.set(ylabel="Number of samples", ylim=(0, 30))

Screenshot of script and plot result

1 个答案:

答案 0 :(得分:2)

在这里,颜色变灰不是由于“饱和度”,而是“alpha”。您可以设置 sns.displot(...., alpha=1)

import seaborn as sns

tips = sns.load_dataset('tips')
sns.displot(data=tips, x='total_bill', hue='day', palette=["#9b59b6", "#ff0000", "#00f0f0", "#00ff00"], alpha=1)

displot with alpha=1

请注意,为相同的 x 值显示多个条形的默认值为 multiple='layer'。使用 alpha=0.4 可以轻松区分不同的层,而使用 alpha=1 的查看者可能会误认为条形是堆叠的。

这里是 multiple='stack' 的样子(注意较大的 y 值):

sns.displot with multiple='stack'

这里有multiple='dodge'

multiple='dodge'

相关问题