8000 now consistent with other Normalize classes · matplotlib/matplotlib@be12dc7 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be12dc7

Browse files
committed
now consistent with other Normalize classes
1 parent 7fab129 commit be12dc7

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/matplotlib/colors.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/matplotlib/tests/test_colors.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_BoundaryNorm():
9494

9595
# Masked arrays
9696
boundaries = [0, 1.1, 2.2]
97-
vals = [-1., np.NaN, 0, 1.4, 9]
97+
vals = np.ma.masked_invalid([-1., np.NaN, 0, 1.4, 9])
9898

9999
# Without interpolation
100100
ncolors = len(boundaries) - 1
@@ -108,13 +108,11 @@ def test_BoundaryNorm():
108108
assert_array_equal(bn(vals), expected)
109109

110110
# Non-trivial masked arrays
111-
vals = [np.Inf, np.NaN]
111+
vals = np.ma.masked_invalid([np.Inf, np.NaN])
112112
assert_true(np.all(bn(vals).mask))
113-
vals = [np.Inf]
113+
vals = np.ma.masked_invalid([np.Inf])
114114
assert_true(np.all(bn(vals).mask))
115115

116-
# Invalid scalar raises an exception
117-
assert_raises(Exception, bn, np.NaN)
118116

119117
def test_LogNorm():
120118
"""

0 commit comments

Comments
 (0)
0