@@ -1252,10 +1252,12 @@ def __init__(self, boundaries, ncolors, clip=False):
1252
1252
as i varies from 0 to len(boundaries)-2,
1253
1253
j goes from 0 to ncolors-1.
1254
1254
1255
- If clip == False, Out-of-range values are mapped
1255
+ Out-of-range values are mapped
1256
1256
to -1 if low and ncolors if high; these are converted
1257
1257
to valid indices by
1258
1258
:meth:`Colormap.__call__` .
1259
+ If clip == True, out-of-range values
1260
+ are mapped to 0 if low and ncolors-1 if high.
1259
1261
"""
1260
1262
self .clip = clip
1261
1263
self .vmin = boundaries [0 ]
@@ -1268,18 +1270,19 @@ def __init__(self, boundaries, ncolors, clip=False):
1268
1270
else :
1269
1271
self ._interp = True
1270
1272
1271
- def __call__ (self , x , clip = None ):
1273
+ def __call__ (self , value , clip = None ):
1272
1274
if clip is None :
1273
1275
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 ))
1277
1280
if clip :
1278
1281
np .clip (xx , self .vmin , self .vmax , out = xx )
1279
1282
max_col = self .Ncmap - 1
1280
1283
else :
1281
1284
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 )
1283
1286
for i , b in enumerate (self .boundaries ):
1284
1287
iret [xx >= b ] = i
1285
1288
if self ._interp :
@@ -1288,7 +1291,7 @@ def __call__(self, x, clip=None):
1288
1291
iret [xx < self .vmin ] = - 1
1289
1292
iret [xx >= self .vmax ] = max_col
1290
1293
ret = ma .array (iret , mask = mask )
1291
- if x . shape == () :
1294
+ if is_scalar :
1292
1295
ret = int (ret [0 ]) # assume python scalar
1293
1296
return ret
1294
1297
0 commit comments