title: Is it possible to control which colors are retrieved from matplotlib colormap?
body: <p>I want to assign colors in a plot to nominal data represented by integers. I want to draw colors from a Qualitative colormap, specifically I want to draw five colors from Set3:</p>
  
  <p><a href="https://i.stack.imgur.com/ZSSvT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZSSvT.png" alt="Matplotlib built-in Qualitative colormaps"></a></p>
  
  <p>The problem is that I want to use the first five colors, but the colormapper normalizes my data, which ranges from 1 to 5 for the five categorical values, and selects the 1st, 4th, 7th, 10th, and 12th colors from the 12-color set.</p>
  
  <p>Basically, <code>matplotlib.cm.get_cmap</code> allows you to specify a number of colors, but normalizes across the range:</p>
  
  <pre class="lang-py prettyprint-override"><code>from matplotlib import cm
  set3_5 = cm.get_cmap("Set3", lut = 5)
  </code></pre>
  
  <p>I want something like <code>matplotlib.colors.ListedColormap</code> which has a parameter <code>N</code> which <em>truncates</em> the color list after <em>N</em> items without normalizing. But I can't figure out how to pass a built-in colormap to <code>ListedColormap</code>.</p>