diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 6401b64dc248..0401fd6734c8 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -275,8 +275,8 @@ def __init__(self, ax, def __str__(self): try: - size = self.get_size() - return f"{type(self).__name__}(size={size!r})" + shape = self.get_shape() + return f"{type(self).__name__}(shape={shape!r})" except RuntimeError: return type(self).__name__ @@ -291,6 +291,15 @@ def get_size(self): return self._A.shape[:2] + def get_shape(self): + """Return the shape of the image as + tuple (numrows, numcols, channels). + """ + if self._A is None: + raise RuntimeError('You must first set the image array') + + return self._A.shape + def set_alpha(self, alpha): """ Set the alpha value used for blending - not supported on all backends.