From ea8f80ab9d047d74dcffec88beea78075fb7c58f Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 13 Apr 2018 09:46:08 -0700 Subject: [PATCH 1/3] FIX: image respect norm limits w/ None --- lib/matplotlib/image.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 81357ecb2cc4..b8331fbea9dd 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -390,22 +390,24 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, # float64's ability to represent changes. Applying # a norm first would be good, but ruins the interpolation # of over numbers. - if self.norm.vmin is not None and self.norm.vmax is not None: - dv = (np.float64(self.norm.vmax) - - np.float64(self.norm.vmin)) - vmid = self.norm.vmin + dv / 2 - newmin = vmid - dv * 1.e7 - if newmin < a_min: - newmin = None - else: - a_min = np.float64(newmin) - newmax = vmid + dv * 1.e7 - if newmax > a_max: - newmax = None - else: - a_max = np.float64(newmax) - if newmax is not None or newmin is not None: - A_scaled = np.clip(A_scaled, newmin, newmax) + vmin = self.norm.vmin if self.norm.vmin is not None else a_min + vmax = self.norm.vmax if self.norm.vmax is not None else a_max + + dv = (np.float64(vmax) - + np.float64(vmin)) + vmid = vmin + dv / 2 + newmin = vmid - dv * 1.e7 + if newmin < a_min: + newmin = None + else: + a_min = np.float64(newmin) + newmax = vmid + dv * 1.e7 + if newmax > a_max: + newmax = None + else: + a_max = np.float64(newmax) + if newmax is not None or newmin is not None: + A_scaled = np.clip(A_scaled, newmin, newmax) A_scaled -= a_min # a_min and a_max might be ndarray subclasses so use From 89c3345f83074e821e5742dcf313f085317cd394 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 13 Apr 2018 10:35:14 -0700 Subject: [PATCH 2/3] FIX: image respect norm limits w/ None --- lib/matplotlib/image.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index b8331fbea9dd..f5869c693243 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -390,12 +390,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, # float64's ability to represent changes. Applying # a norm first would be good, but ruins the interpolation # of over numbers. - vmin = self.norm.vmin if self.norm.vmin is not None else a_min - vmax = self.norm.vmax if self.norm.vmax is not None else a_max - - dv = (np.float64(vmax) - - np.float64(vmin)) - vmid = vmin + dv / 2 + self.norm.autoscale_None(A) + dv = (np.float64(self.norm.vmax) - + np.float64(self.norm.vmin)) + vmid = self.norm.vmin + dv / 2 newmin = vmid - dv * 1.e7 if newmin < a_min: newmin = None From 8d53a8aef661eabfef61d55284832efadf891a09 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 9 May 2018 13:32:27 -0700 Subject: [PATCH 3/3] FIX: image respect norm limits w/ None --- lib/matplotlib/image.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index f5869c693243..b3813eac2b68 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -394,12 +394,13 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, dv = (np.float64(self.norm.vmax) - np.float64(self.norm.vmin)) vmid = self.norm.vmin + dv / 2 - newmin = vmid - dv * 1.e7 + fact = 1e7 if scaled_dtype == np.float64 else 1e4 + newmin = vmid - dv * fact if newmin < a_min: newmin = None else: a_min = np.float64(newmin) - newmax = vmid + dv * 1.e7 + newmax = vmid + dv * fact if newmax > a_max: newmax = None else: @@ -409,7 +410,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, A_scaled -= a_min # a_min and a_max might be ndarray subclasses so use - # asscalar to ensure they are scalars to avoid errors + # asscalar to avoid errors a_min = np.asscalar(a_min.astype(scaled_dtype)) a_max = np.asscalar(a_max.astype(scaled_dtype))