Search code examples
pythonseabornviolin-plotcolor-palette

The color defined in palette is not the same as output in seaborn.violinplot()


I used parameter palette in seaborn.violinplot() to define custom color in the violinplot, here is my code:

from matplotlib import pyplot as plt
from matplotlib.colors import to_rgb
from matplotlib.collections import PolyCollection
import seaborn as sns
import pandas as pd
tips = sns.load_dataset('tips')
ax = sns.violinplot(x="day", y="total_bill", hue="smoker", palette=['#5f82b5', '#D76364'], data=tips, split=True, inner='box')
ax.legend_.remove()
plt.show()

Here is my output:

enter image description here

However, the color in the figure of the hues are #6a84aa and #c87272 (by using color picker), which is not the same as my definition. I also found this problem in sns.barplot(). How to correct this?


Solution

  • From the docs:

    saturation: float, optional

    Proportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to 1 if you want the plot colors to perfectly match the input color.