2

I have two sets of data from which I am separately plotting 2D histograms using matplotlib's hist2d() as in http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html. Now I would like to have the ratio of these two 2D histograms (i.e. the ratio of the frequency). How can I achieve this in matplotlib?

beranger
  • 23
  • 4

1 Answers1

1

Internally hist2d uses numpy.histogram2d. Thus you can compute both histograms using this function, compute the ratio and then plot it using pcolormesh, imshow or similar.

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)
juseg
  • 561
  • 5
  • 6