9

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))

Bar chart
Bar chart

Palette plot
Palette plot

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
BirdLaw
  • 572
  • 6
  • 16

1 Answers1

13

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.

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))

enter image description here

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.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Correct answer though I wouldn't say it's true of "most", just those that draw large patches (which generally look better if they are not as bright). – mwaskom Jun 02 '17 at 18:38
  • @mwaskom Is there a way to set the saturation to 1 by default? When using `seaborn.apionly` this is not affected. And there seems to be no such thing as `sns.set(style="white", saturation=1)`. In general I would consider it to be bad style to fix the style to the actual plotting command. – ImportanceOfBeingErnest Jun 02 '17 at 18:45
  • No, seaborn doesn't define any globals/defaults that matplotlib doesn't. – mwaskom Jun 02 '17 at 18:48
  • Thank you so much. That was driving me crazy – Josh Marks Jan 03 '23 at 03:18