Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c22ddc7

Browse filesBrowse files
committed
Simplify check for tight-bbox finiteness.
`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.)
1 parent b6e8c19 commit c22ddc7
Copy full SHA for c22ddc7

File tree

Expand file treeCollapse file tree

3 files changed

+17
-18
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-18
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ def stale(self, val):
232232
def get_window_extent(self, renderer):
233233
"""
234234
Get the axes bounding box in display space.
235+
236+
The bounding box' width and height are nonnegative.
237+
235238
Subclasses should override for inclusion in the bounding box
236239
"tight" calculation. Default is to return an empty bounding
237240
box at 0, 0.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,9 +4334,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
43344334

43354335
for a in bbox_artists:
43364336
bbox = a.get_tightbbox(renderer)
4337-
if (bbox is not None and
4338-
(bbox.width != 0 or bbox.height != 0) and
4339-
np.isfinite(bbox.width) and np.isfinite(bbox.height)):
4337+
if (bbox is not None
4338+
and 0 < bbox.width < np.inf
4339+
and 0 < bbox.height < np.inf):
43404340
bb.append(bbox)
43414341

43424342
_bbox = mtransforms.Bbox.union(

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,21 +1151,17 @@ def get_tightbbox(self, renderer):
11511151
self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2)
11521152
self.offsetText.set_text(self.major.formatter.get_offset())
11531153

1154-
bb = []
1155-
1156-
for a in [self.label, self.offsetText]:
1157-
bbox = a.get_window_extent(renderer)
1158-
if (np.isfinite(bbox.width) and np.isfinite(bbox.height) and
1159-
a.get_visible()):
1160-
bb.append(bbox)
1161-
bb.extend(ticklabelBoxes)
1162-
bb.extend(ticklabelBoxes2)
1163-
bb = [b for b in bb if ((b.width != 0 or b.height != 0) and
1164-
np.isfinite(b.width) and
1165-
np.isfinite(b.height))]
1166-
if bb:
1167-
_bbox = mtransforms.Bbox.union(bb)
1168-
return _bbox
1154+
bboxes = [
1155+
*(a.get_window_extent(renderer)
1156+
for a in [self.label, self.offsetText]
1157+
if a.get_visible()),
1158+
*ticklabelBoxes,
1159+
*ticklabelBoxes2,
1160+
]
1161+
bboxes = [b for b in bboxes
1162+
if 0 < b.width < np.inf and 0 < b.height < np.inf]
1163+
if bboxes:
1164+
return mtransforms.Bbox.union(bb)
11691165
else:
11701166
return None
11711167

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.