title: set colorbar range with contourf
body: <p>This would appear to be a duplicate of this question:</p>
  <p><a href="https://stackoverflow.com/questions/3373256/set-colorbar-range-in-matplotlib">Set Colorbar Range in matplotlib</a></p>
  <p>Essentially I want to set the <code>colorbar</code> range to set limits, e.g. 0 to 2.  When I use <code>vmin</code> and <code>vmax</code>, the range of colors in <code>contourf</code> is correctly set, but colorbar only shows the clipped range, i.e. the solution in the link doesn't seem to work when using <code>contourf</code>.  Am I missing something obvious?</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  fld=np.random.rand(10,10)
  img=plt.contourf(fld,20,cmap='coolwarm',vmin=0,vmax=2)
  plt.colorbar(img)
  </code></pre>
  <p>Resulting in</p>
  <p><a href="https://i.stack.imgur.com/YNfov.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YNfov.jpg" alt="enter image description here" /></a></p>
  <p>How can I force the colorbar range to be 0 to 2 with <code>contourf</code>?</p>