matplotlib中2D直方图的比率

时间:2015-02-02 11:14:41

标签: matplotlib histogram histogram2d

我有两组数据,我使用matplotlib的hist2d()分别绘制二维直方图,如http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html所示。 现在我想得到这两个2D直方图的比率(即频率比)。我怎样才能在matplotlib中实现这个目标?

1 个答案:

答案 0 :(得分:0)

Internally hist2d使用numpy.histogram2d。因此,您可以使用此函数计算两个直方图,计算比率,然后使用pcolormeshimshow或类似方法绘制直方图。

h1, xedges, yedges = np.histogram2d(x1, y1, bins=bins)
h2, xedges, yedges = np.histogram2d(x2, y2, bins=bins)
h = h1 / h2
pc = ax.pcolorfast(xedges, yedges, h.T)
相关问题