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

Skip to content

Commit c95c964

Browse files
committed
Don't fail on empty autoscale_None.
We reuse the same strategy as in the default Normalize.autoscale_None. First convert the input to an array because that's what np.size and np.ma.min/max do anyways, so it's more efficient to do it just once.
1 parent abdc2be commit c95c964

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

lib/matplotlib/colors.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -961,15 +961,17 @@ def autoscale(self, A):
961961
"""
962962
Set *vmin*, *vmax* to min, max of *A*.
963963
"""
964-
self.vmin = np.ma.min(A)
965-
self.vmax = np.ma.max(A)
964+
A = np.asanyarray(A)
965+
self.vmin = A.min()
966+
self.vmax = A.max()
966967

967968
def autoscale_None(self, A):
968-
' autoscale only None-valued vmin or vmax'
969-
if self.vmin is None and np.size(A) > 0:
970-
self.vmin = np.ma.min(A)
971-
if self.vmax is None and np.size(A) > 0:
972-
self.vmax = np.ma.max(A)
969+
"""autoscale only None-valued vmin or vmax."""
970+
A = np.asanyarray(A)
971+
if self.vmin is None and A.size:
972+
self.vmin = A.min()
973+
if self.vmax is None and A.size:
974+
self.vmax = A.max()
973975

974976
def scaled(self):
975977
'return true if vmin and vmax set'
@@ -1037,14 +1039,14 @@ def autoscale(self, A):
10371039
self.vmax = np.ma.max(A)
10381040

10391041
def autoscale_None(self, A):
1040-
' autoscale only None-valued vmin or vmax'
1042+
"""autoscale only None-valued vmin or vmax."""
10411043
if self.vmin is not None and self.vmax is not None:
10421044
return
10431045
A = np.ma.masked_less_equal(A, 0, copy=False)
1044-
if self.vmin is None:
1045-
self.vmin = np.ma.min(A)
1046-
if self.vmax is None:
1047-
self.vmax = np.ma.max(A)
1046+
if self.vmin is None and A.size:
1047+
self.vmin = A.min()
1048+
if self.vmax is None and A.size:
1049+
self.vmax = A.max()
10481050

10491051

10501052
class SymLogNorm(Normalize):
@@ -1153,13 +1155,14 @@ def autoscale(self, A):
11531155
self._transform_vmin_vmax()
11541156

11551157
def autoscale_None(self, A):
1156-
""" autoscale only None-valued vmin or vmax """
1158+
"""autoscale only None-valued vmin or vmax."""
11571159
if self.vmin is not None and self.vmax is not None:
11581160
pass
1159-
if self.vmin is None:
1160-
self.vmin = np.ma.min(A)
1161-
if self.vmax is None:
1162-
self.vmax = np.ma.max(A)
1161+
A = np.asanyarray(A)
1162+
if self.vmin is None and A.size:
1163+
self.vmin = A.min()
1164+
if self.vmax is None and A.size:
1165+
self.vmax = A.max()
11631166
self._transform_vmin_vmax()
11641167

11651168

@@ -1223,20 +1226,19 @@ def autoscale(self, A):
12231226
self.vmin = 0
12241227
warnings.warn("Power-law scaling on negative values is "
12251228
"ill-defined, clamping to 0.")
1226-
12271229
self.vmax = np.ma.max(A)
12281230

12291231
def autoscale_None(self, A):
1230-
' autoscale only None-valued vmin or vmax'
1231-
if self.vmin is None and np.size(A) > 0:
1232-
self.vmin = np.ma.min(A)
1232+
"""autoscale only None-valued vmin or vmax."""
1233+
A = np.asanyarray(A)
1234+
if self.vmin is None and A.size:
1235+
self.vmin = A.min()
12331236
if self.vmin < 0:
12341237
self.vmin = 0
12351238
warnings.warn("Power-law scaling on negative values is "
12361239
"ill-defined, clamping to 0.")
1237-
1238-
if self.vmax is None and np.size(A) > 0:
1239-
self.vmax = np.ma.max(A)
1240+
if self.vmax is None and A.size:
1241+
self.vmax = A.max()
12401242

12411243

12421244
class BoundaryNorm(Normalize):

0 commit comments

Comments
 (0)