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

Skip to content

Commit 59e550b

Browse files
authored
Merge pull request #11047 from jklymak/fix-image-respect-norm-limits
FIX: image respect norm limits w/ None
2 parents 920295d + 8d53a8a commit 59e550b

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/matplotlib/image.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,26 +390,27 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
390390
# float64's ability to represent changes. Applying
391391
# a norm first would be good, but ruins the interpolation
392392
# of over numbers.
393-
if self.norm.vmin is not None and self.norm.vmax is not None:
394-
dv = (np.float64(self.norm.vmax) -
395-
np.float64(self.norm.vmin))
396-
vmid = self.norm.vmin + dv / 2
397-
newmin = vmid - dv * 1.e7
398-
if newmin < a_min:
399-
newmin = None
400-
else:
401-
a_min = np.float64(newmin)
402-
newmax = vmid + dv * 1.e7
403-
if newmax > a_max:
404-
newmax = None
405-
else:
406-
a_max = np.float64(newmax)
407-
if newmax is not None or newmin is not None:
408-
A_scaled = np.clip(A_scaled, newmin, newmax)
393+
self.norm.autoscale_None(A)
394+
dv = (np.float64(self.norm.vmax) -
395+
np.float64(self.norm.vmin))
396+
vmid = self.norm.vmin + dv / 2
397+
fact = 1e7 if scaled_dtype == np.float64 else 1e4
398+
newmin = vmid - dv * fact
399+
if newmin < a_min:
400+
newmin = None
401+
else:
402+
a_min = np.float64(newmin)
403+
newmax = vmid + dv * fact
404+
if newmax > a_max:
405+
newmax = None
406+
else:
407+
a_max = np.float64(newmax)
408+
if newmax is not None or newmin is not None:
409+
A_scaled = np.clip(A_scaled, newmin, newmax)
409410

410411
A_scaled -= a_min
411412
# a_min and a_max might be ndarray subclasses so use
412-
# asscalar to ensure they are scalars to avoid errors
413+
# asscalar to avoid errors
413414
a_min = np.asscalar(a_min.astype(scaled_dtype))
414415
a_max = np.asscalar(a_max.astype(scaled_dtype))
415416

0 commit comments

Comments
 (0)