8000 Merge pull request #22485 from timhoffm/Axes-str · matplotlib/matplotlib@2e3e27b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e3e27b

Browse files
authored
Merge pull request #22485 from timhoffm/Axes-str
Change string representation of AxesImage
2 parents 91e8ea1 + 3adaf02 commit 2e3e27b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``AxesImage`` string representation
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The string representation of `.AxesImage` changes from
4+
stating the position in the figure ``"AxesImage(80,52.8;496x369.6)"`` to
5+
giving the number of pixels ``"AxesImage(size=(300, 200))"``.

lib/matplotlib/image.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ def __init__(self, ax,
275275

276276
self._internal_update(kwargs)
277277

278+
def __str__(self):
279+
try:
280+
size = self.get_size()
281+
return f"{type(self).__name__}(size={size!r})"
282+
except RuntimeError:
283+
return type(self).__name__
284+
278285
def __getstate__(self):
279286
# Save some space on the pickle by not saving the cache.
280287
return {**super().__getstate__(), "_imcache": None}
@@ -896,8 +903,6 @@ class AxesImage(_ImageBase):
896903
the output image is larger than the input image.
897904
**kwargs : `.Artist` properties
898905
"""
899-
def __str__(self):
900-
return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
901906

902907
def __init__(self, ax,
903908
cmap=None,

0 commit comments

Comments
 (0)
0