8000 Added get_shape method by Lumijek · Pull Request #22510 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Added get_shape method #22510

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 5 commits into from
Closed
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
13 changes: 11 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand All @@ -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).
"""
Comment on lines +295 to +297
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Return the shape of the image as
tuple (numrows, numcols, channels).
"""
"""
Return the shape of the image as tuple (numrows, numcols, channels).
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the numpydoc format for the returns?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to do that but line length exceeded pep8 limit.

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.
Expand Down
0