Skip to content

Deprecate {NonUniformImage,PcolorImage}.is_grayscale. #15394

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

Merged
merged 1 commit into from
Oct 13, 2019
Merged
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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ logging.
``Colorbar.config_axis()``
~~~~~~~~~~~~~~~~~~~~~~~~~~
``Colorbar.config_axis()`` is considered internal. Its use is deprecated.

``NonUniformImage.is_grayscale`` and ``PcolorImage.is_grayscale``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These attributes are deprecated, for consistency with ``AxesImage.is_grayscale``,
which was removed back in Matplotlib 2.0.0. (Note that previously, these
attributes were only available *after rendering the image*).
22 changes: 16 additions & 6 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,11 @@ def _check_unsampled_image(self, renderer):
"""Return False. Do not use unsampled image."""
return False

@cbook.deprecated("3.3")
@property
def is_grayscale(self):
return self._is_grayscale

def make_image(self, renderer, magnification=1.0, unsampled=False):
# docstring inherited
if self._A is None:
Expand All @@ -992,11 +997,11 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
if A.ndim == 2:
if A.dtype != np.uint8:
A = self.to_rgba(A, bytes=True)
self.is_grayscale = self.cmap.is_gray()
self._is_grayscale = self.cmap.is_gray()
else:
A = np.repeat(A[:, :, np.newaxis], 4, 2)
A[:, :, 3] = 255
self.is_grayscale = True
self._is_grayscale = True
else:
if A.dtype != np.uint8:
A = (255*A).astype(np.uint8)
Expand All @@ -1005,7 +1010,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
B[:, :, 0:3] = A
B[:, :, 3] = 255
A = B
self.is_grayscale = False
self._is_grayscale = False
x0, y0, v_width, v_height = self.axes.viewLim.bounds
l, b, r, t = self.axes.bbox.extents
width = (round(r) + 0.5) - (round(l) - 0.5)
Expand Down Expand Up @@ -1115,6 +1120,11 @@ def __init__(self, ax,
if A is not None:
self.set_data(x, y, A)

@cbook.deprecated("3.3")
@property
def is_grayscale(self):
return self._is_grayscale

def make_image(self, renderer, magnification=1.0, unsampled=False):
# docstring inherited
if self._A is None:
Expand All @@ -1134,7 +1144,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
A = self.to_rgba(self._A, bytes=True)
self._rgbacache = A
if self._A.ndim == 2:
self.is_grayscale = self.cmap.is_gray()
self._is_grayscale = self.cmap.is_gray()
else:
A = self._rgbacache
vl = self.axes.viewLim
Expand Down Expand Up @@ -1180,12 +1190,12 @@ def set_data(self, x, y, A):
raise ValueError("A must be 2D or 3D")
if A.ndim == 3 and A.shape[2] == 1:
A.shape = A.shape[:2]
self.is_grayscale = False
self._is_grayscale = False
if A.ndim == 3:
if A.shape[2] in [3, 4]:
if ((A[:, :, 0] == A[:, :, 1]).all() and
(A[:, :, 0] == A[:, :, 2]).all()):
self.is_grayscale = True
self._is_grayscale = True
else:
raise ValueError("3D arrays must have RGB or RGBA as last dim")

Expand Down