From 5e5713c60bc83ad3846cfe16ea3332ee0d7c7e4f Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 8 Oct 2019 20:13:31 +0200 Subject: [PATCH] Deprecate {NonUniformImage,PcolorImage}.is_grayscale. See changelog. --- doc/api/next_api_changes/deprecations.rst | 6 ++++++ lib/matplotlib/image.py | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 050b38afd810..7f80d9c94a48 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -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*). diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 2890b5793344..86391d4314eb 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -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: @@ -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) @@ -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) @@ -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: @@ -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 @@ -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")