title: Defining a discrete colormap for imshow in matplotlib
body: <p>I have a simple image that I'm showing with imshow in matplotlib. I'd like to apply a custom colormap so that values between 0-5 are white, 5-10 are red (very simple colors), etc.  I've tried following this tutorial: </p>
  
  <p><a href="http://assorted-experience.blogspot.com/2007/07/custom-colormaps.html" rel="noreferrer">http://assorted-experience.blogspot.com/2007/07/custom-colormaps.html</a> with the following code:</p>
  
  <pre><code>cdict = {
  'red'  :  ((0., 0., 0.), (0.5, 0.25, 0.25), (1., 1., 1.)),
  'green':  ((0., 1., 1.), (0.7, 0.0, 0.5), (1., 1., 1.)),
  'blue' :  ((0., 1., 1.), (0.5, 0.0, 0.0), (1., 1., 1.))
  }
  
  my_cmap = mpl.colors.LinearSegmentedColormap('my_colormap', cdict, 3)
  
  plt.imshow(num_stars, extent=(min(x), max(x), min(y), max(y)), cmap=my_cmap)
  plt.show()
  </code></pre>
  
  <p>But this ends up showing strange colors, and I only need 3-4 colors that I want to define.  How do I do this?</p>