@@ -1499,12 +1499,27 @@ def __call__(self, value, clip=None):
14991499 max_col = self .Ncmap - 1
15001500 else :
15011501 max_col = self .Ncmap
1502+ # this gives us the bins in the lookup table in the range
1503+ # [0, _n_regions - 1] (the offset is baked in in the init)
15021504 iret = np .digitize (xx , self .boundaries ) - 1 + self ._offset
1505+ # if we have more colors than regions, stretch the region index
1506+ # computed above to full range of the color bins. This will
1507+ # make use skip some of the colors in the middle of the
1508+ # colormap but will use the full range
15031509 if self .Ncmap > self ._n_regions :
1504- if self ._n_regions == 1 :
1510+ # the maximum possible value in iret
1511+ divsor = self ._n_regions - 1
1512+ if divsor == 0 :
1513+ # special case the 1 region case. What we should do here
1514+ # is a bit undefined (as _any_ color in the colormap is
1515+ # justifiable) we go with not adjusting the value (which will
1516+ # either be 0 or 1 depending on if we are extending down)
15051517 scalefac = 1
15061518 else :
1507- scalefac = (self .Ncmap - 1 ) / (self ._n_regions - 1 )
1519+ # otherwise linearly remap the values from the region index
1520+ # to the color index spaces
1521+ scalefac = (self .Ncmap - 1 ) / divsor
1522+ # do the scaling and re-cast to integers
15081523 iret = (iret * scalefac ).astype (np .int16 )
15091524 iret [xx < self .vmin ] = - 1
15101525 iret [xx >= self .vmax ] = max_col
0 commit comments