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

Skip to content

Commit 4e988f5

Browse files
authored
Merge pull request #26335 from eendebakpt/imshow
Optimize imshow
2 parents dd40f48 + ea53f0d commit 4e988f5

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/matplotlib/cbook.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ def safe_masked_invalid(x, copy=False):
731731
# copy with the byte order swapped.
732732
x = x.byteswap(inplace=copy).newbyteorder('N') # Swap to native order.
733733
try:
734-
xm = np.ma.masked_invalid(x, copy=False)
735-
xm.shrink_mask()
734+
xm = np.ma.masked_where(~(np.isfinite(x)), x, copy=False)
736735
except TypeError:
737736
return x
738737
return xm

lib/matplotlib/cm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,5 +735,6 @@ def _ensure_cmap(cmap):
735735
cmap_name = cmap if cmap is not None else mpl.rcParams["image.cmap"]
736736
# use check_in_list to ensure type stability of the exception raised by
737737
# the internal usage of this (ValueError vs KeyError)
738-
_api.check_in_list(sorted(_colormaps), cmap=cmap_name)
738+
if cmap_name not in _colormaps:
739+
_api.check_in_list(sorted(_colormaps), cmap=cmap_name)
739740
return mpl.colormaps[cmap_name]

lib/matplotlib/colors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,12 @@ def autoscale(self, A):
13901390
def autoscale_None(self, A):
13911391
"""If vmin or vmax are not set, use the min/max of *A* to set them."""
13921392
A = np.asanyarray(A)
1393+
1394+
if isinstance(A, np.ma.MaskedArray):
1395+
# we need to make the distinction between an array, False, np.bool_(False)
1396+
if A.mask is False or not A.mask.shape:
1397+
A = A.data
1398+
13931399
if self.vmin is None and A.size:
13941400
self.vmin = A.min()
13951401
if self.vmax is None and A.size:

0 commit comments

Comments
 (0)