Python Plot numpy.historogram2d()

Python Plot numpy.historogram2d(),python,numpy,matplotlib,Python,Numpy,Matplotlib,我想知道是否可以使用matplotlib.pyplot.hist2d绘制numpy.histogram2d()的输出?在一维情况下,这可以通过使用: counts, bins = np.histogram(something, bins=no_bins, range=(range_min, range_max)) plt.hist(bins[:-1], bins, weights=counts) 二维情况有类似的解决方案吗?我不想用上面建议的方法绘制二维历史 这背后的想法是,我想对初始直方图

我想知道是否可以使用matplotlib.pyplot.hist2d绘制numpy.histogram2d()的输出?在一维情况下,这可以通过使用:

counts, bins = np.histogram(something, bins=no_bins, range=(range_min, range_max))

plt.hist(bins[:-1], bins, weights=counts)
二维情况有类似的解决方案吗?我不想用上面建议的方法绘制二维历史 这背后的想法是,我想对初始直方图进行一些校正(即使用另一个2d直方图中的数据逐点进行背景减法),然后绘制校正后的直方图


非常感谢

绘制二维柱状图通常使用。如果您习惯于根或其他一些绘图库,请特别注意为
原点
范围
提供的参数

绘制二维柱状图通常使用。如果您习惯于根或其他一些绘图库,请特别注意为
原点
范围
提供的参数

以下解决方案按预期工作:

counts_bkg, bins_x_bkg, bins_y_bkg = np.histogram2d(x_bkg, y_bkg, bins=(x_bins, ybins))
counts, bins_x, bins_y = np.histogram2d(x, y, bins=(x_bins, y_bins))

diff = counts - counts_bkg
diffT = diff.T

fig, ax = plt.subplots(1)
pc = ax.pcolorfast(bins_x, bins_y, diffT)
plt.show()

以下解决方案按预期工作:

counts_bkg, bins_x_bkg, bins_y_bkg = np.histogram2d(x_bkg, y_bkg, bins=(x_bins, ybins))
counts, bins_x, bins_y = np.histogram2d(x, y, bins=(x_bins, y_bins))

diff = counts - counts_bkg
diffT = diff.T

fig, ax = plt.subplots(1)
pc = ax.pcolorfast(bins_x, bins_y, diffT)
plt.show()
,您可以找到如何使用matplotlib函数
imshow
pcolormesh
非均匀图像绘制
np.historogram2d()
输出的三个示例

,您可以找到三个示例,说明如何使用matplotlib函数
imshow
pcolormesh
非均匀图像绘制
np.historogram2d()的输出


可能
plt.contourf
可能
plt.contourf