8000 Change string representation of AxesImage by timhoffm · Pull Request #22485 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Change string representation of AxesImage #22485

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
Feb 18, 2022
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/22485-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``AxesImage`` string representation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string representation of `.AxesImage` changes from
stating the position in the figure ``"AxesImage(80,52.8;496x369.6)"`` to
giving the number of pixels ``"AxesImage(size=(300, 200))"``.
9 changes: 7 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ def __init__(self, ax,

self._internal_update(kwargs)

def __str__(self):
try:
size = self.get_size()
return f"{type(self).__name__}(size={size!r})"
except RuntimeError:
return type(self).__name__

def __getstate__(self):
# Save some space on the pickle by not saving the cache.
return {**super().__getstate__(), "_imcache": None}
Expand Down Expand Up @@ -896,8 +903,6 @@ class AxesImage(_ImageBase):
the output image is larger than the input image.
**kwargs : `.Artist` properties
"""
def __str__(self):
return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)

def __init__(self, ax,
cmap=None,
Expand Down
0