我想知道是否有可能使用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)对于二维情况,是否有类似的解决方案?我不想用https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html上建议的方法绘制二维直方图,这背后的想法是我想对初始直方图应用一些校正(即使用来自另一个二维直方图的数据逐个进行背景减去),然后绘制校正后的直方图。
首先要感谢大家!
发布于 2019-12-07 04:54:12
绘制二维直方图通常是使用imshow()完成的。如果您习惯于根目录或其他绘图库,请特别注意为origin和extent提供的参数。
发布于 2019-12-08 02:46:38
以下解决方案按预期工作:
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()发布于 2021-05-24 06:20:32
https://stackoverflow.com/questions/59220131
复制相似问题