title: How do I use colorbar with hist2d in matplotlib.pyplot?
body: <p>I want to do something similar to <a href="http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html" rel="noreferrer">http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html</a> but I've read that using pylab for code other than in python interactive mode is bad practice so I'd like to do this with matplotlib.pyplot. However, I can't figure out how to make this code work using pyplot. Using, pylab, the example given is</p>
  
  <pre><code>from matplotlib.colors import LogNorm
  from pylab import *
  
  #normal distribution center at x=0 and y=5
  x = randn(100000)
  y = randn(100000)+5
  
  hist2d(x, y, bins=40, norm=LogNorm())
  colorbar()
  show()
  </code></pre>
  
  <p>I've tried a lot like </p>
  
  <pre><code>import matplotlib.pyplot as plt
  fig = plt.figure()
  ax1 = fig.add_subplot(1,1,1)
  h1 = ax1.hist2d([1,2],[3,4])
  </code></pre>
  
  <p>and from here I've tried everything from <code>plt.colorbar(h1)</code> <code>plt.colorbar(ax1)</code> <code>plt.colorbar(fig)</code> <code>ax.colorbar()</code> etc etc and I can't get anything to work.</p>
  
  <p>In general, I'm honestly not really clear on the relationship between pylab and pyplot, even after reading <a href="http://matplotlib.org/faq/usage_faq.html" rel="noreferrer">http://matplotlib.org/faq/usage_faq.html</a>. For example <code>show()</code> in pylab seems to become <code>plt.show()</code> in pyplot, but for some reason <code>colorbar</code> doesn't become <code>plt.colorbar()</code>? </p>
  
  <p>For example, </p>