Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5238ac

Browse files
committed
FIX: handle degenerate case of all equal values
1 parent 856556f commit b5238ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/matplotlib/image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
387387
A_scaled = np.empty(A.shape, dtype=scaled_dtype)
388388
A_scaled[:] = A
389389
A_scaled -= a_min
390-
A_scaled /= ((a_max - a_min) / 0.8)
390+
if a_min != a_max:
391+
A_scaled /= ((a_max - a_min) / 0.8)
391392
A_scaled += 0.1
392393
A_resampled = np.zeros((out_height, out_width),
393394
dtype=A_scaled.dtype)
@@ -408,7 +409,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
408409
# below, but possibly clipped in the case of higher order
409410
# interpolation + drastically changing data.
410411
A_resampled -= 0.1
411-
A_resampled *= ((a_max - a_min) / 0.8)
412+
if a_min != a_max:
413+
A_resampled *= ((a_max - a_min) / 0.8)
412414
A_resampled += a_min
413415
# if using NoNorm, cast back to the original datatype
414416
if isinstance(self.norm, mcolors.NoNorm):

0 commit comments

Comments
 (0)