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 b0b9d4b

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 b0b9d4b
Copy full SHA for b0b9d4b

File tree

Expand file treeCollapse file tree

3 files changed

+8
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-11
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
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,8 +4335,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
43354335
for a in bbox_artists:
43364336
bbox = a.get_tightbbox(renderer)
43374337
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)):
4338+
0 < bbox.width < np.inf and 0 < bbox.height < np.inf):
43404339
bb.append(bbox)
43414340

43424341
_bbox = mtransforms.Bbox.union(

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,20 +1152,15 @@ def get_tightbbox(self, renderer):
11521152
self.offsetText.set_text(self.major.formatter.get_offset())
11531153

11541154
bb = []
1155-
11561155
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()):
1156+
if a.get_visible():
1157+
bbox = a.get_window_extent(renderer)
11601158
bb.append(bbox)
11611159
bb.extend(ticklabelBoxes)
11621160
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))]
1161+
bb = [b for b in bb if 0 < b.width < np.inf and 0 < b.height < np.inf]
11661162
if bb:
1167-
_bbox = mtransforms.Bbox.union(bb)
1168-
return _bbox
1163+
return mtransforms.Bbox.union(bb)
11691164
else:
11701165
return None
11711166

0 commit comments

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