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
ENH: Added __repr__ for Figure #9379
ENH: Added __repr__ for Figure #9379
Conversation
lib/matplotlib/figure.py
Outdated
clsname=self.__class__.__name__, | ||
h=self.bbox.size[0], w=self.bbox.size[1], | ||
naxes=len(self.axes), | ||
ax_plural='is' if len(self.axes) == 1 else 'es' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The singular of Axes is Axes (... for matplotlib, Axis is something completely different (sad but true)).
TBH I would just have the suptitle and be done with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think just saying "with one axes" is probably fine and technically more accurate, would it be possible to change that @richardjgowers ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstansby ok I've changed this
19766d9
to
d443db1
Compare
lib/matplotlib/figure.py
Outdated
@@ -273,6 +273,13 @@ class Figure(Artist): | |||
def __str__(self): | |||
return "Figure(%gx%g)" % tuple(self.bbox.size) | |||
|
|||
def __repr__(self): | |||
return "<{clsname} size {h:g}x{w:g} with {naxes} axes>".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capital Axes, though, referring to the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
PR Summary
Adds a better repr to Figure
Eg:
(Maybe) Fixes Issue #9372
Anything else that should go into the repr? Maybe dpi?
Could also do
__str__ == __repr__
seeing as they're nearly identical?PR Checklist