Sunday 20 August 2023

Plotting a gaussian fit to a histgram with displot or histplot

I've decided to give seaborn version 0.11.0 a go! Playing around with the displot function, which will replace distplot, as I understand it. I'm just trying to figure out how to plot a gaussian fit on to a histogram. Here's some example code.

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

With distplot I could do:

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

enter image description here

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

enter image description here

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



from Plotting a gaussian fit to a histgram with displot or histplot

No comments:

Post a Comment