【发布时间】:2025-09-17 19:30:05
【问题描述】:
请问,我想知道如何绘制正态分布图。
这是我的代码:
import numpy as np
import scipy.stats as stats
import pylab as pl
h=[27.3,27.6,27.5,27.6,27.3,27.6,27.9,27.5,27.4,27.5,27.5,27.4,27.1,27.0,27.3,27.4]
fit = stats.norm.pdf(h, np.mean(h), np.std(h)) #this is a fitting indeed
pl.plot(h,fit,'-o')
pl.hist(h,density=True) #use this to draw histogram of your data
pl.show() #use may also need add this
我试过了,但是曲线很粗糙。
【问题讨论】:
-
您想在
plot()和hist()中使用range(len(fit))而不是h作为x值吗?
标签: python numpy matplotlib scipy