包更新了,移除了这个属性,换用下面代码即可
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()