@@ -1252,10 +1252,12 @@ def __init__(self, boundaries, ncolors, clip=False):
12521252 as i varies from 0 to len(boundaries)-2,
12531253 j goes from 0 to ncolors-1.
12541254
1255- If clip == False, Out-of-range values are mapped
1255+ Out-of-range values are mapped
12561256 to -1 if low and ncolors if high; these are converted
12571257 to valid indices by
12581258 :meth:`Colormap.__call__` .
1259+ If clip == True, out-of-range values
1260+ are mapped to 0 if low and ncolors-1 if high.
12591261 """
12601262 self .clip = clip
12611263 self .vmin = boundaries [0 ]
@@ -1268,18 +1270,19 @@ def __init__(self, boundaries, ncolors, clip=False):
12681270 else :
12691271 self ._interp = True
12701272
1271- def __call__ (self , x , clip = None ):
1273+ def __call__ (self , value , clip = None ):
12721274 if clip is None :
12731275 clip = self .clip
1274- x = ma .masked_invalid (x , copy = False )
1275- mask = ma .getmaskarray (x )
1276- xx = np .atleast_1d (x .filled (self .vmax + 1 ))
1276+
1277+ xx , is_scalar = self .process_value (value )
1278+ mask = ma .getmaskarray (xx )
1279+ xx = np .atleast_1d (xx .filled (self .vmax + 1 ))
12771280 if clip :
12781281 np .clip (xx , self .vmin , self .vmax , out = xx )
12791282 max_col = self .Ncmap - 1
12801283 else :
12811284 max_col = self .Ncmap
1282- iret = np .atleast_1d ( np . zeros (x .shape , dtype = np .int16 ) )
1285+ iret = np .zeros (xx .shape , dtype = np .int16 )
12831286 for i , b in enumerate (self .boundaries ):
12841287 iret [xx >= b ] = i
12851288 if self ._interp :
@@ -1288,7 +1291,7 @@ def __call__(self, x, clip=None):
12881291 iret [xx < self .vmin ] = - 1
12891292 iret [xx >= self .vmax ] = max_col
12901293 ret = ma .array (iret , mask = mask )
1291- if x . shape == () :
1294+ if is_scalar :
12921295 ret = int (ret [0 ]) # assume python scalar
12931296 return ret
12941297
0 commit comments