From dcb37088718d5dbc200c86a4062c484b3a8c5c4c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 24 Jun 2021 01:45:04 -0400 Subject: [PATCH] Backport PR #20488: FIX: Include 0 when checking lognorm vmin --- lib/matplotlib/image.py | 6 +++--- lib/matplotlib/tests/test_image.py | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 98e2b5eb790a..efa50758daa1 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -534,9 +534,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, # we have re-set the vmin/vmax to account for small errors # that may have moved input values in/out of range s_vmin, s_vmax = vrange - if isinstance(self.norm, mcolors.LogNorm): - if s_vmin < 0: - s_vmin = max(s_vmin, np.finfo(scaled_dtype).eps) + if isinstance(self.norm, mcolors.LogNorm) and s_vmin <= 0: + # Don't give 0 or negative values to LogNorm + s_vmin = np.finfo(scaled_dtype).eps with cbook._setattr_cm(self.norm, vmin=s_vmin, vmax=s_vmax, diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 9657968de7eb..38182f5a8a46 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -1213,23 +1213,24 @@ def test_imshow_quantitynd(): fig.canvas.draw() +@pytest.mark.parametrize('x', [-1, 1]) @check_figures_equal(extensions=['png']) -def test_huge_range_log(fig_test, fig_ref): - data = np.full((5, 5), -1, dtype=np.float64) +def test_huge_range_log(fig_test, fig_ref, x): + # parametrize over bad lognorm -1 values and large range 1 -> 1e20 + data = np.full((5, 5), x, dtype=np.float64) data[0:2, :] = 1E20 ax = fig_test.subplots() - im = ax.imshow(data, norm=colors.LogNorm(vmin=100, vmax=data.max()), - interpolation='nearest', cmap='viridis') + ax.imshow(data, norm=colors.LogNorm(vmin=1, vmax=data.max()), + interpolation='nearest', cmap='viridis') - data = np.full((5, 5), -1, dtype=np.float64) + data = np.full((5, 5), x, dtype=np.float64) data[0:2, :] = 1000 - cmap = copy(plt.get_cmap('viridis')) - cmap.set_under('w') ax = fig_ref.subplots() - im = ax.imshow(data, norm=colors.Normalize(vmin=100, vmax=data.max()), - interpolation='nearest', cmap=cmap) + cmap = plt.get_cmap('viridis').with_extremes(under='w') + ax.imshow(data, norm=colors.Normalize(vmin=1, vmax=data.max()), + interpolation='nearest', cmap=cmap) @check_figures_equal() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy