8000 FIX: carry through the over/under in resampling · matplotlib/matplotlib@0a16672 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a16672

Browse files
committed
FIX: carry through the over/under in resampling
Use the same trick for carrying through the masked points to use the green and blue channels to carry the under/over markers.
1 parent c0d4321 commit 0a16672

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/matplotlib/image.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
361361
# If the image is greyscale, convert to RGBA with the
362362
# correct alpha channel for resizing
363363
rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
364-
rgba[..., 0:3] = np.expand_dims(A, 2)
364+
rgba[..., 0] = A # normalized data
365+
rgba[..., 1] = A < 0 # under data
366+
# TODO, ask the norm or colormap what this threshold should be
367+
rgba[..., 2] = A > 1 # over data
365368
if A.dtype.kind == 'f':
366369
rgba[..., 3] = ~A.mask
367370
else:
@@ -393,8 +396,13 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
393396
if created_rgba_mask:
394397
# Convert back to a masked greyscale array so
395398
# colormapping works correctly
399+
hid_output = output
396400
output = np.ma.masked_array(
397-
output[..., 0], output[..., 3] < 0.5)
401+
hid_output[..., 0], hid_output[..., 3] < 0.5)
402+
# relabel under data
403+
output[hid_output[..., 1] > .5] = -1
404+
# relabel over data
405+
output[hid_output[..., 2] > .5] = 2
398406

399407
output = self.to_rgba(output, bytes=True, norm=False)
400408

0 commit comments

Comments
 (0)
0