Home > database >  How to show the y-axis of seaborn displot as percentage
How to show the y-axis of seaborn displot as percentage

Time:11-09

I'm using seaborn.displot to display a distribution of scores for a group of participants.

Is it possible to have the y axis show an actual percentage (example below)?

This is required by the audience for the data. Currently it is done in excel but It would be more useful in python.

import seaborn as sns

data = sns.load_dataset('titanic')

p = sns.displot(data=data, x='age', hue='sex', height=4, kind='kde')

enter image description here

Desired Format

enter image description here

CodePudding user response:

As mentioned by @JohanC, the y axis for a KDE is a enter image description here

But your "desired plot" actually doesn't look like a density at all, it looks like a histogram plotted with a line instead of bars. You can get that with element="poly":

sns.displot(
    data=tips, x="total_bill", hue="sex",
    kind="hist", stat="percent", element="poly", fill=False,
)

enter image description here

CodePudding user response:

  • See enter image description here

    Don't do the following, as explained

    kind='kde': enter image description here

  • Related