Skip to content

Commit 0ac66f3

Browse files
authored
Merge pull request #15394 from anntzer/is_grayscale
Deprecate {NonUniformImage,PcolorImage}.is_grayscale.
2 parents e672bf8 + 5e5713c commit 0ac66f3

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

doc/api/next_api_changes/deprecations.rst

+6
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ logging.
1616
``Colorbar.config_axis()``
1717
~~~~~~~~~~~~~~~~~~~~~~~~~~
1818
``Colorbar.config_axis()`` is considered internal. Its use is deprecated.
19+
20+
``NonUniformImage.is_grayscale`` and ``PcolorImage.is_grayscale``
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
These attributes are deprecated, for consistency with ``AxesImage.is_grayscale``,
23+
which was removed back in Matplotlib 2.0.0. (Note that previously, these
24+
attributes were only available *after rendering the image*).

lib/matplotlib/image.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,11 @@ def _check_unsampled_image(self, renderer):
982982
"""Return False. Do not use unsampled image."""
983983
return False
984984

985+
@cbook.deprecated("3.3")
986+
@property
987+
def is_grayscale(self):
988+
return self._is_grayscale
989+
985990
def make_image(self, renderer, magnification=1.0, unsampled=False):
986991
# docstring inherited
987992
if self._A is None:
@@ -992,11 +997,11 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
992997
if A.ndim == 2:
993998
if A.dtype != np.uint8:
994999
A = self.to_rgba(A, bytes=True)
995-
self.is_grayscale = self.cmap.is_gray()
1000+
self._is_grayscale = self.cmap.is_gray()
9961001
else:
9971002
A = np.repeat(A[:, :, np.newaxis], 4, 2)
9981003
A[:, :, 3] = 255
999-
self.is_grayscale = True
1004+
self._is_grayscale = True
10001005
else:
10011006
if A.dtype != np.uint8:
10021007
A = (255*A).astype(np.uint8)
@@ -1005,7 +1010,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
10051010
B[:, :, 0:3] = A
10061011
B[:, :, 3] = 255
10071012
A = B
1008-
self.is_grayscale = False
1013+
self._is_grayscale = False
10091014
x0, y0, v_width, v_height = self.axes.viewLim.bounds
10101015
l, b, r, t = self.axes.bbox.extents
10111016
width = (round(r) + 0.5) - (round(l) - 0.5)
@@ -1115,6 +1120,11 @@ def __init__(self, ax,
11151120
if A is not None:
11161121
self.set_data(x, y, A)
11171122

1123+
@cbook.deprecated("3.3")
1124+
@property
1125+
def is_grayscale(self):
1126+
return self._is_grayscale
1127+
11181128
def make_image(self, renderer, magnification=1.0, unsampled=False):
11191129
# docstring inherited
11201130
if self._A is None:
@@ -1134,7 +1144,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
11341144
A = self.to_rgba(self._A, bytes=True)
11351145
self._rgbacache = A
11361146
if self._A.ndim == 2:
1137-
self.is_grayscale = self.cmap.is_gray()
1147+
self._is_grayscale = self.cmap.is_gray()
11381148
else:
11391149
A = self._rgbacache
11401150
vl = self.axes.viewLim
@@ -1180,12 +1190,12 @@ def set_data(self, x, y, A):
11801190
raise ValueError("A must be 2D or 3D")
11811191
if A.ndim == 3 and A.shape[2] == 1:
11821192
A.shape = A.shape[:2]
1183-
self.is_grayscale = False
1193+
self._is_grayscale = False
11841194
if A.ndim == 3:
11851195
if A.shape[2] in [3, 4]:
11861196
if ((A[:, :, 0] == A[:, :, 1]).all() and
11871197
(A[:, :, 0] == A[:, :, 2]).all()):
1188-
self.is_grayscale = True
1198+
self._is_grayscale = True
11891199
else:
11901200
raise ValueError("3D arrays must have RGB or RGBA as last dim")
11911201

0 commit comments

Comments
 (0)