简体   繁体   中英

Plot of normal curve not…normal

I am plotting both a distribution of test scores and a fitted curve to these test scores:

h = sorted(data['Baseline'])  #sorted
fit = stats.norm.pdf(h, np.mean(h), np.std(h))
plt.plot(h,fit,'-o')
plt.hist(h,normed=True)      #use this to draw histogram of your data
plt.show()

The plot of the pdf, however, does not look normal (see kink in curve near x=60). See output:

在此处输入图片说明

I'm not sure what is going on here...any help appreciated. Is this because the normal line is being drawn between supplied observations? Can provide you with the actual data if needed, there are only 60 observations.

Yes, you evaluate the norm-pdf on the overservation. You would instead want to create some other data like

h = sorted(data['Baseline'])  #sorted
x = np.linspace(h.min(), h.max(), 151)

fit = stats.norm.pdf(x, np.mean(h), np.std(h))

plt.plot(x,fit,'-')
plt.hist(h,normed=True) 
plt.show()

Note however, that the data does not look normally distributed at all. So potentially you would rather fit a different distribution, or maybe perform a kernel density estimate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM