所有 matplotlib examples使用 hist()
生成数据集,将数据集提供给带有一些 bin(可能非均匀间隔)的 hist
函数,该函数自动计算然后绘制直方图。
我已经有了直方图数据,我只是想绘制它,我该怎么做?!例如,我有垃圾箱(半开范围用方括号和弯括号表示法表示),
[0, 1) 0
[1, 2) 3
[2, 3) 8
[3, 4) 6
[4, 5) 2
[5, 6) 3
[6, 7) 1
[7, 8) 0
最佳答案
也许权重参数会对您的问题有所帮助。
import matplotlib.pyplot as plt
a= [1,2,3,4,5,6,7,8,9]
b= [5,3,4,5,3,2,1,2,3]
plt.hist(a,9, weights=b)
plt.show()
或者,正如 tcaswell 所说,您可以制作条形图并更改 x 轴。
Using matplotlib how could I plot a histogram with given data in python
是一个链接。
关于python - 来自已经分箱的数据的直方图,我有分箱和频率值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17238087/