python-3.x - 如何更改seaborn distplot的颜色饱和度?

标签 python-3.x seaborn

我已经安装了最新版本的 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))
Screenshot of script and plot result

最佳答案

在这里,颜色变灰不是由于“饱和度”,而是“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'

关于python-3.x - 如何更改seaborn distplot的颜色饱和度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67443657/

相关文章:

python - 如何将 x 和 y 轴上的值更改为 seaborn pairplot 中的单词?

python-3.x - 在视频中显示帧的裁剪部分:函数 cv::imshow 中的错误 (-215) size.width>0 && size.height>0

python - 将 group() 转换为 float 或 int 格式

python - 获取具有不同子列表数据类型的列表元素的交集

python - 使用 Seaborn 条形图分离(并保留)重复的分类数据?

python - 共享轴并删除 matplotlib 子图中未使用的

python - 即使在Macintosh上安装了GhostScript,Python <没有这样的文件或目录:'gs'>错误*问题仍然存在!*

python-3.x - 如何修复 Colaboratory 中的 zipfile 读取错误?

python-3.x - scatter_kws 和 line_kws 在 seaborn lmplot 中做什么

python - future 警告 : Using a non-tuple sequence for multidimensional indexing is deprecated use `arr[tuple(seq)]`