Skip to content

Commit faf9684

Browse files
committed
Merge pull request #11047 from jklymak/fix-image-respect-norm-limits
FIX: image respect norm limits w/ None Conflicts: lib/matplotlib/image.py - keep changes backported from master. Looks like conflict was due to some white-space clean up done on master.
1 parent eb489f6 commit faf9684

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
@@ -401,26 +401,27 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
401401
# float64's ability to represent changes. Applying
402402
# a norm first would be good, but ruins the interpolation
403403
# of over numbers.
404-
if self.norm.vmin is not None and self.norm.vmax is not None:
405-
dv = (np.float64(self.norm.vmax) -
406-
np.float64(self.norm.vmin))
407-
vmid = self.norm.vmin + dv / 2
408-
newmin = vmid - dv * 1.e7
409-
if newmin < a_min:
410-
newmin = None
411-
else:
412-
a_min = np.float64(newmin)
413-
newmax = vmid + dv * 1.e7
414-
if newmax > a_max:
415-
newmax = None
416-
else:
417-
a_max = np.float64(newmax)
418-
if newmax is not None or newmin is not None:
419-
A_scaled = np.clip(A_scaled, newmin, newmax)
404+
self.norm.autoscale_None(A)
405+
dv = (np.float64(self.norm.vmax) -
406+
np.float64(self.norm.vmin))
407+
vmid = self.norm.vmin + dv / 2
408+
fact = 1e7 if scaled_dtype == np.float64 else 1e4
409+
newmin = vmid - dv * fact
410+
if newmin < a_min:
411+
newmin = None
412+
else:
413+
a_min = np.float64(newmin)
414+
newmax = vmid + dv * fact
415+
if newmax > a_max:
416+
newmax = None
417+
else:
418+
a_max = np.float64(newmax)
419+
if newmax is not None or newmin is not None:
420+
A_scaled = np.clip(A_scaled, newmin, newmax)
420421

421422
A_scaled -= a_min
422423
# a_min and a_max might be ndarray subclasses so use
423-
# asscalar to ensure they are scalars to avoid errors
424+
# asscalar to avoid errors
424425
a_min = np.asscalar(a_min.astype(scaled_dtype))
425426
a_max = np.asscalar(a_max.astype(scaled_dtype))
426427

0 commit comments

Comments
 (0)