直方图原程序
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
mu,sigma = 100, 20 #均值和标准差
a = np.random.normal(mu, sigma, size=100)
plt.hist(a, 20, normed=1, histtype='stepfilled', facecolor='b', alpha=0.75)
plt.title('Histogram')
plt.show()
运行时显示,‘Polygon’ object has no property ‘normed’
经查找,normed=1的属性已经取消,可以使用density=True。
运行无问题。
正确代码
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
mu,sigma = 100, 20 #均值和标准差
a = np.random.normal(mu, sigma, size=100)
plt.hist(a, 20, density=True, histtype='stepfilled', facecolor='b', alpha=0.75)
plt.title('Histogram')
plt.show()
结果