我有这个数据:如何绘制一个柱状图,其中柱高是Python中柱宽的函数?
[-152, -132, -132, -128, -122, -121, -120, -113, -112, -108,
-107, -107, -106, -106, -106, -105, -101, -101, -99, -89, -87,
-86, -83, -83, -80, -80, -79, -74, -74, -74, -71, -71, -69,
-67, -67, -65, -62, -61, -60, -60, -59, -55, -54, -54, -52,
-50, -49, -48, -48, -47, -44, -43, -38, -37, -35, -34, -34,
-29, -27, -27, -26, -24, -24, -19, -19, -19, -19, -18, -16,
-16, -16, -15, -14, -14, -12, -12, -12, -4, -1, 0, 0, 1, 2, 7,
14, 14, 14, 14, 18, 18, 19, 24, 29, 29, 41, 45, 51, 72, 150, 155]
我想通过使用直方图与这些箱绘制它:
[-160,-110,-90,-70,-40,-10,20,50,80,160]
我用这个代码为:
import matplotlib.pyplot as plt
...
plt.hist(data, bins)
plt.show()
但是这个图的问题是,酒吧的高度不是根据酒吧的宽度,因为频率应该象征酒吧(见this page)的面积。那么我怎么能绘制这种类型的直方图呢? 在此先感谢。
一般直方图不具有约束杆的区域是频率的量度。很多时候,酒吧的高度被用作频率测量。 matplotlib的hist函数完成后者。所以你不能使用该功能。无论如何,将数据分析与可视化分开是一个好主意。因此,首先通过例如计算直方图。使用['numpy.histogram'](https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html),然后绘制它,例如通过['matplotlib.pyplot.hist()'](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist) – ImportanceOfBeingErnest
我认为这个问题是一个好的开始:http://stackoverflow.com/questions/17429669/how-to-plot-a-histogram-with-unequal-widths-without-computing-it-from-raw-data –