title: How to normalise heat maps
body: <p>I am trying to normalise heat maps that are derived from a <code>2dhistogram</code>. I'd like the distributions to be relative, regardless of the amount of data points. </p>
  
  <p>The attached code contains two sets of data. One has more x,y coordinates compared to the other. While the numbers are random is it possible to normalise these plots so the density represents the distribution not the frequency. Using the example below, x1-y1 will appear to have a lot more variation due to the amount of samples. Even though the underlying variation is similar to x2-y2</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import random
  import numpy as np
  
  fig, ((ax1, ax2)) = plt.subplots(1,2)
  
  x1 = [random.randrange(1,101,1) for _ in range (10000)]
  y1 = [random.randrange(1,101,1) for _ in range (10000)]
  
  x2 = [random.randrange(1,100,1) for _ in range (1000)]
  y2 = [random.randrange(1,100,1) for _ in range (1000)]
  
  zi, xi, yi = np.histogram2d(x1, y1, bins=40, normed = False)
  im = ax1.imshow(zi, interpolation = 'gaussian', origin = 'lower', cmap = 'jet')
  
  zi, xi, yi = np.histogram2d(x2, y2, bins=40, normed = False)
  im = ax2.imshow(zi, interpolation = 'gaussian', origin = 'lower', cmap = 'jet')
  </code></pre>
  
  <p>Can I normalise the rows by determining the maximum intensity or count in each bin and use that as a reference point and plot there other data from ranges 0 - 1?</p>
  
  <p>Note: This isn't related to the above code but I'll attach examples to give a visual of what I'm hoping to achieve. My code produces the following images:</p>
  
  <p><a href="https://i.stack.imgur.com/LQ50o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LQ50o.png" alt="enter image description here"></a></p>
  
  <p>Whilst not reproducible with the above code, these images are produced as such:</p>
  
  <pre><code>C_f50,x,y,p = plt.hist2d(Con_F50X, Con_F50Y, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax9.imshow(C_f50.T, interpolation = 'gaussian', cmap = 'jet')
  
  C_fmid,x,y,p = plt.hist2d(Con_FMIDX, Con_FMIDY, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax10.imshow(C_fmid.T, interpolation = 'gaussian', cmap = 'jet')
  
  C_dmid,x,y,p = plt.hist2d(Con_DMIDX, Con_DMIDY, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax11.imshow(C_dmid.T, interpolation = 'gaussian', cmap = 'jet')
  
  C_d50,x,y,p = plt.hist2d(Con_D50X, Con_D50Y, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax12.imshow(C_d50.T, interpolation = 'gaussian', cmap = 'jet')
  </code></pre>
  
  <p>The next set of images uses the <code>vmin</code> and <code>vmax</code> detailed by @filippo in the answers section.</p>
  
  <p><a href="https://i.stack.imgur.com/N3e5l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N3e5l.png" alt="enter image description here"></a></p>
  
  <p>As you can see the density has changed remarkably. the main difference is the <code>vmin/vmax</code> function. It gets these measures from the first plot (C_f50).</p>
  
  <p>What I'm trying to understand is if there is another method to normalise the density of all plots from a separate point. The above used vmin/vmax from the first plot. But obviously if it's normalised from this plot the density won't change.</p>
  
  <pre><code>C_f50,x,y,p = plt.hist2d(Con_F50X, Con_F50Y, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax9.imshow(C_f50.T, interpolation = 'gaussian', cmap = 'jet')
  
  C_fmid,x,y,p = plt.hist2d(Con_FMIDX, Con_FMIDY, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax10.imshow(C_fmid.T, interpolation = 'gaussian', cmap = 'jet',vmin=C_f50.min(), vmax=C_f50.max())
  
  C_dmid,x,y,p = plt.hist2d(Con_DMIDX, Con_DMIDY, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax11.imshow(C_dmid.T, interpolation = 'gaussian', cmap = 'jet', vmin=C_f50.min(), vmax=C_f50.max())
  
  C_d50,x,y,p = plt.hist2d(Con_D50X, Con_D50Y, bins = 40, range = np.array([(-85, 85), (4, 140)]))
  ax12.imshow(C_d50.T, interpolation = 'gaussian', cmap = 'jet',vmin=C_f50.min(), vmax=C_f50.max())
  </code></pre>
  
  <p>Does any of this make sense?</p>