【发布时间】:2021-12-01 09:23:55
【问题描述】:
我在网上看到了两种方法,但是在尝试了这两种方法之后,您会认为图应该看起来一样,但实际上并不一样。
方法一:
n, bins, patches = plt.hist(SP[0], 30, facecolor='green', alpha=1, histtype='stepfilled')
方法二:
counts, bins = np.histogram(SP[0])
plt.hist(bins[:-1], bins=30, weights=counts)
【问题讨论】:
-
输入似乎是离散的,而
plt.hist用于连续数据。因此,您的第一个直方图格式不正确。对于您的第二个绘图,除了使用错误的bin=参数外,如果您真的想使用weights=,您会遇到舍入问题。
标签: python matplotlib histogram