[Python] Plotting a gaussian fit to a histogram in displot or histplot

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    How can I plot a gaussian fit onto a histplot, as previously done by the deprecated distplot?

    import seaborn as sns
    import numpy as np
    from scipy.stats import norm
    x = np.random.normal(size=500) * 0.1


    With distplot I could do:

    sns.distplot(x, kde=False, fit=norm)


    [​IMG]

    But how to go about it in displot or histplot?

    So far the closest I've come to is:

    sns.histplot(x,stat="probability", bins=30, kde=True, kde_kws={"bw_adjust":3})


    [​IMG]

    But I think this just increases the smoothening of the plotted kde, which isn't exactly what I'm going for.

    Continue reading...

Compartilhe esta Página