title: matplotlib scatter plot with custom cmap - colors not right
body: <p>So I'm following a pattern to create a custom color map and cbar for my scatter plot. I'm creating 4 subplots each covering a different range of a parameter that is used to give the dots their color. The values for this parameter range from 1e-10 to 1.0.</p>
  
  <p>I do the following:</p>
  
  <pre><code>cmap = plt.cm.jet
  # extract all colors from the .jet map
  cmaplist = [cmap(i) for i in range(cmap.N)]
  # force the first color entry to be grey
  cmaplist[0] = (.5,.5,.5,1.0)
  # create the new map
  cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)
  
  # define the bins and normalize
  bounds = np.linspace(-10,0,11)
  norm   = mpl.colors.BoundaryNorm(bounds, cmap.N)
  ...
  fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row', figsize=(20,20))
  ...
  ax1.scatter(xcoord[rng1], ycoord[rng1], s=massFilt[rng1]/dotNorm,
                      c=np.ma.log10(Zfilt[rng1]), cmap=cmap)
  ax2.scatter(xcoord[rng2],ycoord[rng2], s=massFilt[rng2]/dotNorm,
                      c=np.ma.log10(Zfilt[rng2]), cmap=cmap)
  ax3.scatter(xcoord[rng3], ycoord[rng3], s=massFilt[rng3]/dotNorm,
                      c=np.ma.log10(Zfilt[rng3]), cmap=cmap)
  ax4.scatter(xcoord[rng4], ycoord[rng4], s=massFilt[rng4]/dotNorm,
                      c=np.ma.log10(Zfilt[rng4]), cmap=cmap)
  </code></pre>
  
  <p>where the rngs are defined as</p>
  
  <pre><code>rng1 = (Zfilt &lt; 2.e-7)
  rng2 = ((Zfilt &gt;= 2.e-7) &amp; (Zfilt &lt; 1.e-4))
  rng3 = ((Zfilt &gt;= 1.e-4) &amp; (Zfilt &lt; 1.e-2))
  rng4 = (Zfilt &gt;= 1.e-2)
  </code></pre>
  
  <p>So the first panel includes only those less than 2e-7 and the points are all colored correctly... I've verified that the filter is working correctly: for instance Zfilt[rng4] only contains points where Zfilt > 1e-2 ... <strong><em>But somehow I'm seeing colors in rng2 and rng3 that should only be used for rng1</em></strong>!!?? See attached.</p>
  
  <p>Any ideas? What am I doing wrong?</p>
  
  <p><a href="https://i.stack.imgur.com/DdsWU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DdsWU.png" alt="All points in panel 2 (top right) ARE less than 1e-4 and should be green, blue or grey... NOT RED?!?"></a></p>
  
  <p>Here's a sample of Zfilt[rng2] -</p>
  
  <pre><code>Z values rng2  [-4.23451696 -4.35974369 -5.18479833 -6.17304647 -4.48839191 -5.16774006
   -4.12047222 -6.11491263 -5.81392662 -4.6491248  -4.75038775 -5.06640103
   -4.20821705 -4.12556725 -4.58661378 -4.17023495 -5.40845781 -4.54981553
   -5.82830048 -4.11185471 -4.43155534 -6.17025186 -4.88154584 -5.00024704
   -4.13626926 -5.57797731 -6.0617742  -5.33182163 -5.44963247 -5.88409509
   -6.16903327 -5.70808154 -4.88578943 -4.00873256 -4.1457824  -4.45174817
   -5.43829583 -4.32470978 -4.11634754 -5.1141915  -5.13310282 -4.15469421
  ...
  </code></pre>