2020-12-01
阅读量:
1605
matplotlib.mlab模块里没有normpdf这个属性呢
这时因为matpolot包更新了,移除了normpdf这个方法,可以用scipy.stats中的norm方法代替
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, density=True)
# 添加拟合曲线
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)


暂无数据
推荐帖子
0条评论
0条评论
0条评论