8000 FIX: Include 0 when checking lognorm vmin · matplotlib/matplotlib@4760953 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4760953

Browse files
committed
FIX: Include 0 when checking lognorm vmin
Change vmin check to less than or equal to 0 rather than strictly less than.
1 parent 2a3037f commit 4760953

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
532532
# we have re-set the vmin/vmax to account for small errors
533533
# that may have moved input values in/out of range
534534
s_vmin, s_vmax = vrange
535-
if isinstance(self.norm, mcolors.LogNorm):
536-
if s_vmin < 0:
537-
s_vmin = max(s_vmin, np.finfo(scaled_dtype).eps)
535+
if isinstance(self.norm, mcolors.LogNorm) and s_vmin < 10000 span class="pl-c1 x"><= 0:
536+
# Don't give 0 or negative values to LogNorm
537+
s_vmin = np.finfo(scaled_dtype).eps
538538
with cbook._setattr_cm(self.norm,
539539
vmin=s_vmin,
540540
vmax=s_vmax,

lib/matplotlib/tests/test_image.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ def test_imshow_quantitynd():
12341234

12351235

12361236
@check_figures_equal(extensions=['png'])
1237-
def test_huge_range_log(fig_test, fig_ref):
1237+
def test_huge_range_log_negative(fig_test, fig_ref):
12381238
data = np.full((5, 5), -1, dtype=np.float64)
12391239
data[0:2, :] = 1E20
12401240

@@ -1252,6 +1252,23 @@ def test_huge_range_log(fig_test, fig_ref):
12521252
interpolation='nearest', cmap=cmap)
12531253

12541254

1255+
@check_figures_equal(extensions=['png'])
1256+
def test_huge_range_log(fig_test, fig_ref):
1257+
data = np.full((5, 5), 1, dtype=np.float64)
1258+
data[0:2, :] = 1E20
1259+
1260+
ax = fig_test.subplots()
1261+
im = ax.imshow(data, norm=colors.LogNorm(vmin=1, vmax=data.max()),
1262+
interpolation='nearest', cmap='viridis')
1263+
1264+
data = np.full((5, 5), 1, dtype=np.float64)
1265+
data[0:2, :] = 1000
1266+
1267+
ax = fig_ref.subplots()
1268+
im = ax.imshow(data, norm=colors.Normalize(vmin=1, vmax=data.max()),
1269+
interpolation='nearest', cmap='viridis')
1270+
1271+
12551272
@check_figures_equal()
12561273
def test_spy_box(fig_test, fig_ref):
12571274
# setting up reference and test

0 commit comments

Comments
 (0)
0