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

Skip to content

Commit 46b39ab

Browse files
authored
Merge pull request #28130 from anntzer/omoa
Clarify the role of out_mask and out_alpha in _make_image.
2 parents 68c87d7 + af2fb9c commit 46b39ab

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/matplotlib/image.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,19 +518,17 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
518518
if isinstance(self.norm, mcolors.NoNorm):
519519
A_resampled = A_resampled.astype(A.dtype)
520520

521+
# Compute out_mask (what screen pixels include "bad" data
522+
# pixels) and out_alpha (to what extent screen pixels are
523+
# covered by data pixels: 0 outside the data extent, 1 inside
524+
# (even for bad data), and intermediate values at the edges).
521525
mask = (np.where(A.mask, np.float32(np.nan), np.float32(1))
522526
if A.mask.shape == A.shape # nontrivial mask
523527
else np.ones_like(A, np.float32))
524528
# we always have to interpolate the mask to account for
525529
# non-affine transformations
526530
out_alpha = _resample(self, mask, out_shape, t, resample=True)
527531
del mask # Make sure we don't use mask anymore!
528-
# Agg updates out_alpha in place. If the pixel has no image
529-
# data it will not be updated (and still be 0 as we initialized
530-
# it), if input data that would go into that output pixel than
531-
# it will be `nan`, if all the input data for a pixel is good
532-
# it will be 1, and if there is _some_ good data in that output
533-
# pixel it will be between [0, 1] (such as a rotated image).
534532
out_mask = np.isnan(out_alpha)
535533
out_alpha[out_mask] = 1
536534
# Apply the pixel-by-pixel alpha values if present

0 commit comments

Comments
 (0)