如何更改绘图颜色饱和度

Jac*_*hen 5 python colors seaborn displot

我已经安装了最新版本的seaborn(0.11.1)。当我使用自定义颜色绘制历史记录时,它显示的颜色与我预期的不同(请参阅 sns.palplot 的颜色)。对于某些 api,它有一个饱和参数,但对于 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))
Run Code Online (Sandbox Code Playgroud)

脚本和剧情结果截图

Joh*_*anC 6

在这里,颜色变灰不是由于“饱和度”,而是由于“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)
Run Code Online (Sandbox Code Playgroud)

绘制 alpha=1

请注意,显示同一 x 值的多个条形的默认值为multiple='layer'。使用alpha=0.4不同的层可以很容易地区分,而alpha=1观看者可能会混淆条形是堆叠的。

如下multiple='stack'所示(注意较大的 y 值):

sns.displot 与 multiple='stack'

这里有multiple='dodge'

多重='闪避'