2020-05-09
阅读量:
1176
采用mlab中的normpdf生成高斯曲线,提示module 'matplotlib.mlab' has no attribute 'normpdf'

这是因为随着版本更新,mlab中这个属性已经移除了,可以采用使用norm.pdf 为替代的方式
import matplotlib.mlab as mlab
from scipy.stats import norm
mu = 100 # 均值
sigma = 15 # 标准差
x = mu + sigma * np.random.randn(1000)
n, bins, patches = plt.hist(x, 50,normed=1)
# 添加拟合曲线
y = norm.pdf(bins, mu, sigma)
plt.plot(bins, y, '--')
plt.xlabel('Smarts')
plt.ylabel('Probability density')
plt.title(r'Histogram of IQ: $\mu=100$, $\sigma=15$')
# 调整间距以防止ylabel被覆盖
plt.tight_layout()
plt.show()
输出结果为:







评论(0)


暂无数据
推荐帖子
2条评论
6条评论
7条评论