Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c582e4

Browse files
committed
colors: avoid problems with bad values under the mask when color mapping
This change should have no effect on any plot, but it avoids warnings that can arise when an inf occurs under a mask.
1 parent 1bf4dde commit 8c582e4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/matplotlib/colors.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,10 @@ def __call__(self, X, alpha=None, bytes=False):
510510
xa = np.array([X])
511511
else:
512512
vtype = 'array'
513-
xma = ma.array(X, copy=False)
514-
mask_bad = xma.mask
515-
xa = xma.data.copy() # Copy here to avoid side effects.
513+
xma = ma.array(X, copy=True) # Copy here to avoid side effects.
514+
mask_bad = xma.mask # Mask will be used below.
515+
xa = xma.filled() # Fill to avoid infs, etc.
516516
del xma
517-
# masked values are substituted below; no need to fill them here
518517

519518
if xa.dtype.char in np.typecodes['Float']:
520519
# Treat 1.0 as slightly less than 1.

0 commit comments

Comments
 (0)