【发布时间】:2015-04-01 07:48:32
【问题描述】:
我有两组数据,我分别使用 matplotlib 的 hist2d() 绘制二维直方图,如http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html。 现在我想知道这两个二维直方图的比率(即频率的比率)。如何在 matplotlib 中实现这一点?
【问题讨论】:
标签: matplotlib histogram histogram2d
我有两组数据,我分别使用 matplotlib 的 hist2d() 绘制二维直方图,如http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html。 现在我想知道这两个二维直方图的比率(即频率的比率)。如何在 matplotlib 中实现这一点?
【问题讨论】:
标签: matplotlib histogram histogram2d
Internally hist2d 使用 numpy.histogram2d。因此,您可以使用此函数计算两个直方图,计算比率,然后使用pcolormesh、imshow 或类似方法绘制它。
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)
【讨论】: