title: matplotlib: How can you specify colour levels in a 2D historgram
body: <p>I would like to plot a 2D histogram that includes both positive and negative numbers.  I have the following code which uses pcolormesh but I am unable to specify the color levels to force the white color to corresponds to zero (i.e., I want my colorbar to be symmetric around zero).  I've also tried imshow.</p>
  
  <p>I know you can specify colour levels in plt.contour and plt.contourf but I can't find a way to plot the 2D histogram using blocks.  </p>
  
  <p>Any advice would be greatly appreciated.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from matplotlib import cm as CM
  
  fig = plt.figure()
  
  # create an example histogram which is asymmetrical around zero
  x = np.random.rand(400)
  y = np.random.rand(400)    
  Z, xedges, yedges = np.histogram2d(x, y, bins=10)   
  Z = Z - 2.
  
  plt.pcolormesh(xedges, yedges, Z, cmap=CM.RdBu_r)
  
  plt.colorbar()
  plt.savefig('test.png')
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7AMZr.png" alt="enter image description here"></p>