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 0b21c7c

Browse filesBrowse files
authored
Merge pull request #18458 from tacaswell/fix_huge_imshow_range
Fix huge imshow range
2 parents 80550e1 + b23708a commit 0b21c7c
Copy full SHA for 0b21c7c

File tree

3 files changed

+29
-4
lines changed
Filter options

3 files changed

+29
-4
lines changed

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,6 @@ def __init__(self, *args, **kwargs):
12861286
**{k: ba.arguments.pop(k) for k in ["vmin", "vmax", "clip"]})
12871287
self._scale = scale_cls(axis=None, **ba.arguments)
12881288
self._trf = self._scale.get_transform()
1289-
self._inv_trf = self._trf.inverted()
12901289

12911290
def __call__(self, value, clip=None):
12921291
value, is_scalar = self.process_value(value)
@@ -1318,7 +1317,10 @@ def inverse(self, value):
13181317
raise ValueError("Invalid vmin or vmax")
13191318
rescaled = value * (t_vmax - t_vmin)
13201319
rescaled += t_vmin
1321-
return self._inv_trf.transform(rescaled).reshape(np.shape(value))
1320+
return (self._trf
1321+
.inverted()
1322+
.transform(rescaled)
1323+
.reshape(np.shape(value)))
13221324

13231325
Norm.__name__ = base_norm_cls.__name__
13241326
Norm.__qualname__ = base_norm_cls.__qualname__

‎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
@@ -530,9 +530,13 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
530530
resampled_masked = np.ma.masked_array(A_resampled, out_mask)
531531
# we have re-set the vmin/vmax to account for small errors
532532
# that may have moved input values in/out of range
533+
s_vmin, s_vmax = vrange
534+
if isinstance(self.norm, mcolors.LogNorm):
535+
if s_vmin < 0:
536+
s_vmin = max(s_vmin, np.finfo(scaled_dtype).eps)
533537
with cbook._setattr_cm(self.norm,
534-
vmin=vrange[0],
535-
vmax=vrange[1],
538+
vmin=s_vmin,
539+
vmax=s_vmax,
536540
):
537541
output = self.norm(resampled_masked)
538542
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
@@ -1209,3 +1209,22 @@ def test_imshow_quantitynd():
12091209
ax.imshow(arr)
12101210
# executing the draw should not raise an exception
12111211
fig.canvas.draw()
1212+
1213+
1214+
@check_figures_equal(extensions=['png'])
1215+
def test_huge_range_log(fig_test, fig_ref):
1216+
data = np.full((5, 5), -1, dtype=np.float64)
1217+
data[0:2, :] = 1E20
1218+
1219+
ax = fig_test.subplots()
1220+
im = ax.imshow(data, norm=colors.LogNorm(vmin=100, vmax=data.max()),
1221+
interpolation='nearest', cmap='viridis')
1222+
1223+
data = np.full((5, 5), -1, dtype=np.float64)
1224+
data[0:2, :] = 1000
1225+
1226+
cm = copy(plt.get_cmap('viridis'))
1227+
cm.set_under('w')
1228+
ax = fig_ref.subplots()
1229+
im = ax.imshow(data, norm=colors.Normalize(vmin=100, vmax=data.max()),
1230+
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.