title: How to force matplotlib to write specific RGB values in each pixel in numpy array?
body: <p>I have code that generates images with filled circles, that can be one of 10 colors using <code>plt.fill</code>, with the X and Y coordinates of one <code>circle</code> at a time from <code>circle_list</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>for i in range(0, R.shape[0]):
     radius = R[i]
     circle = circle_list[i]
     color = assigned_colors[i]
     plt.fill(circle[:, 0], circle[:, 1], facecolor=color)
  </code></pre>
  
  <p><code>assigned_colors</code> is a list of the same length as <code>R.shape[0]</code> (the total number of circles to draw) with one of the colors specified in <code>color_list</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>color_list = [(.14,.33,.49), (.08,.41,.27), (.37,.76,.35), (.92,.58,.13),
                (.90,.25,.09), (.96,.75,.12), (.74,.09,.15), (.80,.76,.56), 
                (.56,.70,.72), (.77,.71,.76)]
  </code></pre>
  
  <p>I then save this image as a numpy ndarray: </p>
  
  <pre class="lang-py prettyprint-override"><code>plt.savefig('test.png', dpi=350)
  arr = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
  arr = arr.reshape(fig.canvas.get_width_height()[::-1] + (3,))
  np.save('arr.npy', arr)
  </code></pre>
  
  <p>This all works great, but I would for some analysis I do, I would like to use the unique RGB values specified for filling the circles as unique IDs. However, when I load the array, and look at the unique colors, I observe <em>many</em> more than expected:</p>
  
  <pre class="lang-py prettyprint-override"><code>circles_npy = np.load('./arr.npy')
  len(np.unique(circles_npy.reshape(-1, circles_npy.shape[2]), axis=0))
  
  &gt;&gt;&gt; 2854
  </code></pre>
  
  <p>If I draw the image, it visually looks like the 10 colors I specified are drawn, but why are the RGB values so different? Is there a way to force matplotlib to only use those <em>exact</em> values, plus a background color? I would have expected this to return 11 (for the 10 possible colors plus the white background. I don't understand what's going on here and how can I use colors as labels in the array? Ideally what I am looking for is a unique value for every color in the image array. </p>