Matplotlib 的hist http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist说“计算并绘制 x 的直方图”。我想做一个情节without首先计算任何东西。我有箱宽度(不相等)和每个箱中的总量,并且我想绘制频率数量直方图。
例如,用数据
cm Frequency
65-75 2
75-80 7
80-90 21
90-105 15
105-110 12
它应该制作这样的情节:
http://www.gcsemathstutor.com/histograms.php http://www.gcsemathstutor.com/histograms.php
其中块的面积代表每个类别中的频率。
与大卫·茨威克(David Zwicker)从事相同的工作:
import numpy as np
import matplotlib.pyplot as plt
freqs = np.array([2, 7, 21, 15, 12])
bins = np.array([65, 75, 80, 90, 105, 110])
widths = bins[1:] - bins[:-1]
heights = freqs.astype(np.float)/widths
plt.fill_between(bins.repeat(2)[1:-1], heights.repeat(2), facecolor='steelblue')
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)