Matplotlib 的 hist
说“计算并绘制 x 的直方图”。我想在不先计算任何东西的情况下制作一个情节。我有 bin 宽度(不相等)和每个 bin 中的总量,我想绘制频率-数量直方图。
例如,随着数据
cm Frequency
65-75 2
75-80 7
80-90 21
90-105 15
105-110 12
它应该是这样的情节:
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()
关于matplotlib - 如何在不根据原始数据计算的情况下绘制宽度不等的直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429669/