Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8508463

Browse filesBrowse files
dopplershifttacaswell
authored andcommitted
Backport PR matplotlib#18458: Fix huge imshow range
Merge pull request matplotlib#18458 from tacaswell/fix_huge_imshow_range Fix huge imshow range Conflicts: lib/matplotlib/colors.py - had spurious commit in the initial PR which re-factored code not on the 3.3.x branch lib/matplotlib/tests/test_image.py - conflicts from many tests added to bottom of test_image.py on default branch
1 parent 254f062 commit 8508463
Copy full SHA for 8508463

File tree

2 files changed

+25
-2
lines changed
Filter options

2 files changed

+25
-2
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,13 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
534534
resampled_masked = np.ma.masked_array(A_resampled, out_mask)
535535
# we have re-set the vmin/vmax to account for small errors
536536
# that may have moved input values in/out of range
537+
s_vmin, s_vmax = vrange
538+
if isinstance(self.norm, mcolors.LogNorm):
539+
if s_vmin < 0:
540+
s_vmin = max(s_vmin, np.finfo(scaled_dtype).eps)
537541
with cbook._setattr_cm(self.norm,
538-
vmin=vrange[0],
539-
vmax=vrange[1],
542+
vmin=s_vmin,
543+
vmax=s_vmax,
540544
):
541545
output = self.norm(resampled_masked)
542546
else:

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,3 +1117,22 @@ def test_exact_vmin():
11171117
@pytest.mark.flaky
11181118
def test_https_imread_smoketest():
11191119
v = mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
1120+
1121+
1122+
@check_figures_equal(extensions=['png'])
1123+
def test_huge_range_log(fig_test, fig_ref):
1124+
data = np.full((5, 5), -1, dtype=np.float64)
1125+
data[0:2, :] = 1E20
1126+
1127+
ax = fig_test.subplots()
1128+
im = ax.imshow(data, norm=colors.LogNorm(vmin=100, vmax=data.max()),
1129+
interpolation='nearest', cmap='viridis')
1130+
1131+
data = np.full((5, 5), -1, dtype=np.float64)
1132+
data[0:2, :] = 1000
1133+
1134+
cm = copy(plt.get_cmap('viridis'))
1135+
cm.set_under('w')
1136+
ax = fig_ref.subplots()
1137+
im = ax.imshow(data, norm=colors.Normalize(vmin=100, vmax=data.max()),
1138+
interpolation='nearest', cmap=cm)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.