I am creating a histrogram (frecuency vs. count) and I want to add kernel density estimate line in a different colour. How can I do this? I want to change the colour for example
sns.histplot(data=penguins, x="flipper_length_mm", kde=True)
Example taken from https://seaborn.pydata.org/generated/seaborn.histplot.html
histplot
'sline_kws={...}
is meant to change the appearance of the kde line. However, the current seaborn version doesn't allow changing the color that way, probably because the color goes together with thehue
parameter (althoughhue
isn't used in this case).In seaborn's github, it is suggested to draw the
histplot
and thekdeplot
separately. For both to match in the y-direction, it is necessary to usehistplot
withstat='density'
(thekdeplot
doesn't have a parameter to usehistplot
's defaultstat='count'
).If the
count
statistics is really needed, an alternative is to change the line color via matplotlib: