我已经安装了最新版本的 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))
最佳答案
在这里,颜色变灰不是由于“饱和度”,而是“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)
请注意,默认为相同的 x 值显示多个条形是
multiple='layer'
.使用 alpha=0.4
不同的层可以很容易地区分,同时使用 alpha=1
观看者可能会认为条形图是堆叠的。这是如何
multiple='stack'
看起来像(注意较大的 y 值):在这里与
multiple='dodge'
:关于python-3.x - 如何更改seaborn distplot的颜色饱和度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67443657/