python - 来自已经分箱的数据的直方图,我有分箱和频率值

标签 python matplotlib histogram

所有 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/

相关文章:

python - 有没有办法断言两个字符串除了 python 中的一部分之外是相同的?

python - 如何使用 Python 子进程在 Windows 中进行搜索

python - 使用 matplotlib 在 sankey 图中连接两个以上的系统让我错位

gnuplot - gnuplot 中 2D 直方图(热图)的 3D View

python - FFMPEG 无法在 Python subprocess.Popen 中工作,但可以在命令行中工作

Python 3 pyplot.hold 已弃用

python - 如何增加条形图上日期的 xticks/标签的频率?

python - 让 axvline 以某个 y 值结束

python - dataframe.hist() 具有不同的 bin 大小

python - 将方法传递给 Python 中的函数