Skip to content

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

Merged
merged 1 commit into from
Feb 18, 2019
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
3 changes: 3 additions & 0 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def stale(self, val):
def get_window_extent(self, renderer):
"""
Get the axes bounding box in display space.

The bounding box' width and height are nonnegative.

Subclasses should override for inclusion in the bounding box
"tight" calculation. Default is to return an empty bounding
box at 0, 0.
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4334,9 +4334,9 @@ 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)):
if (bbox is not None
and 0 < bbox.width < np.inf
and 0 < bbox.height < np.inf):
bb.append(bbox)

_bbox = mtransforms.Bbox.union(
Expand Down
26 changes: 11 additions & 15 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,21 +1151,17 @@ def get_tightbbox(self, renderer):
self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2)
self.offsetText.set_text(self.major.formatter.get_offset())

bb = []

for a in [self.label, self.offsetText]:
bbox = a.get_window_extent(renderer)
if (np.isfinite(bbox.width) and np.isfinite(bbox.height) and
Copy link
Contributor Author

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

a.get_visible()):
bb.append(bbox)
bb.extend(ticklabelBoxes)
bb.extend(ticklabelBoxes2)
bb = [b for b in bb if ((b.width != 0 or b.height != 0) and
np.isfinite(b.width) and
np.isfinite(b.height))]
if bb:
_bbox = mtransforms.Bbox.union(bb)
return _bbox
bboxes = [
*(a.get_window_extent(renderer)
for a in [self.label, self.offsetText]
if a.get_visible()),
*ticklabelBoxes,
*ticklabelBoxes2,
]
bboxes = [b for b in bboxes
if 0 < b.width < np.inf and 0 < b.height < np.inf]
if bboxes:
return mtransforms.Bbox.union(bboxes)
else:
return None

Expand Down