Seaborn图表的颜色与调色板指定的颜色不同 [英] Seaborn chart colors are different than those specified by palette
问题描述
为什么海图颜色与调色板指定的颜色不同?
Why are seaborn chart colors different from the colors specified by the palette?
以下两个图表显示了条形图上显示的颜色与调色板图中显示的颜色之间的差异.您可以仔细查看一下条形图上的颜色,使其明亮度/饱和度略微降低.
The following two charts show the difference between the colors as they appear on a bar chart, and the colors as they appear in the palette plot. You can see if yo ulook carefully, that the colors on the bar chart are slightly less bright/saturated.
为什么这些不同?如何使条形图具有与调色板中指定的颜色完全相同的颜色?
Why are these different, and how can I get the bar chart to have the exact same colors as the ones specified in the palette?
import seaborn as sns
sns.set(style="white")
titanic = sns.load_dataset("titanic")
colors = ["windows blue", "amber", "greyish", "faded green", "dusty
purple"]
ax = sns.countplot(x="class", data=titanic,
palette=sns.xkcd_palette(colors))
sns.palplot(sns.xkcd_palette(colors))
条形图
调色板情节
Palette plot
推荐答案
许多seaborn绘图命令的参数为saturation
,其默认值为0.75
.它将HSL色彩空间中的色彩饱和度(S)(从0到1)设置为给定值.
Many seaborn plotting commands have an argument saturation
, whose default value is 0.75
. It sets the saturation (S) of the colors in the HSL colorspace (ranging from 0 to 1) to the given value.
在计数图中将此参数设置为1
将在两个图中为您提供相同的颜色.
Setting this parameter to 1
in the countplot will give you the same colors in both plots.
ax = sns.countplot(x="class", data=titanic, palette=sns.xkcd_palette(colors), saturation=1)
sns.palplot(sns.xkcd_palette(colors))
此默认去饱和度的原因是,许多人认为对比度较低的图更具吸引力.这也是为什么seaborn的默认背景不是白色而是一些蓝灰色的原因.毕竟,这当然是口味的问题.
The reason for this default desaturation is that many people consider a plot with less contrast to be more appealing. That is also why the default background in seaborn is not white but some bluish gray. After all, this is of course a question of taste.
这篇关于Seaborn图表的颜色与调色板指定的颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!