matplotlib里带的hist直方图工具默认是各个bin的频率,也可设置成normed或density,这是概率密度函数,而不是probability,要想画成各个bin高度和为1,也就是各个bin出现的概率,需要设置weights这个参数,具体如下:
import numpy as np
import math
import matplotlib.pyplot as plt
import os
weights = np.ones_like(area) / float(len(area))
plt.hist(area,bins=20,weights=weights,facecolor='blue', alpha=0.75)
plt.xlabel('Maximum rainfall')plt.ylabel('Probability')
plt.title('Histogram of maximum rainfall for warm sector rainstorms')
plt.savefig("D:\\research\\pics\\statistic_warmsectorcases\\warm_secor_rainstorms_maximum_rainfall.png")
参考:https://stackoverflow.com/questions/3866520/plotting-histograms-whose-bar-heights-sum-to-1-in-matplotlib