I have a 1 dimensional array. I can compute the "mean" and "standard deviation" of this sample and plot the "Normal distribution" but I have a problem:
I want to plot the data and Normal distribution in the same figure.
I dont know how to plot both the data and the normal distribution.
Any Idea about "Gaussian probability density function in scipy.stats"?
s = np.std(array)
m = np.mean(array)
plt.plot(norm.pdf(array,m,s))
This question is related to
python
numpy
matplotlib
scipy
To see both the normal distribution and your actual data you should plot your data as a histogram, then draw the probability density function over this. See the example on https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.random.normal.html for exactly how to do this.
There is a much simpler way to do it using seaborn:
import seaborn as sns
from scipy.stats import norm
data = norm.rvs(5,0.4,size=1000) # you can use a pandas series or a list if you want
sns.distplot(data)
plt.show()
for more information:seaborn.distplot
Here you are not fitting a normal distribution. Replacing sns.distplot(data)
by sns.distplot(data, fit=norm, kde=False)
should do the trick.
Source: Stackoverflow.com