10000 FIX: do invalid masking in to_rgba not set_data by tacaswell · Pull Request #6070 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: do invalid masking in to_rgba not set_data #6070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,15 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
except AttributeError:
# e.g., x is not an ndarray; so try mapping it
pass

# This is the normal case, mapping a scalar array:
x = ma.asarray(x)
x = cbook.safe_masked_invalid(x)
if norm:
x = self.norm(x)
rgba = self.cmap(x, alpha=alpha, bytes=bytes)
# For floating-point greyscale images, we treat negative as
# transparent so we copy that over to the alpha channel
if x.ndim == 2 and x.dtype.kind == 'f':
rgba[:, :, 3][x < 0.0] = 0

return rgba

def set_array(self, A):
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ def set_data(self, A):
"""
# check if data is PIL Image without importing Image
if hasattr(A, 'getpixel'):
self._A = pil_to_array(A)
else:
self._A = cbook.safe_masked_invalid(A)
A = pil_to_array(A)

self._A = np.asanyarray(A)

if (self._A.dtype != np.uint8 and
not np.can_cast(self._A.dtype, np.float)):
Expand Down
0