-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Simplify check for tight-bbox finiteness. #13427
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
Conversation
for a in [self.label, self.offsetText]: | ||
bbox = a.get_window_extent(renderer) | ||
if (np.isfinite(bbox.width) and np.isfinite(bbox.height) and |
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.
this finiteness check is redundant with the one below
lib/matplotlib/axes/_base.py
Outdated
@@ -4335,8 +4335,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True, | |||
for a in bbox_artists: | |||
bbox = a.get_tightbbox(renderer) | |||
if (bbox is not None and | |||
(bbox.width != 0 or bbox.height != 0) and | |||
np.isfinite(bbox.width) and np.isfinite(bbox.height)): | |||
0 < bbox.width < np.inf and 0 < bbox.height < np.inf): |
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.
Optional, but might be easier to read when wrapping the height check to a separate line.
lib/matplotlib/axis.py
Outdated
@@ -1152,20 +1152,15 @@ def get_tightbbox(self, renderer): | |||
self.offsetText.set_text(self.major.formatter.get_offset()) | |||
|
|||
bb = [] |
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.
While we're at it, could be renamed to bboxes
. Optional.
both comments handled |
Is it worth doing |
The values can be
See #13426 |
But... that's the point here: these are places that check |
`0 < bbox.width < np.inf` is as explicit as `bbox.width != 0 and np.isfinite(bbox.width)`, shorter, and faster (not that it is a bottleneck, though). (It works because bboxes are oriented to have nonnegative widths and heights.)
🐑 Sorry, was sleepy and got confused about the polarity we were looking at here. |
Thanks @anntzer |
0 < bbox.width < np.inf
is as explicit asbbox.width != 0 and np.isfinite(bbox.width)
, shorter, and faster (not that it is abottleneck, though). (It works because bboxes are oriented to have
nonnegative widths and heights.)
PR Summary
PR Checklist