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 a33422b

Browse filesBrowse files
authored
Merge pull request #13427 from anntzer/isfinite
MNT: Simplify check for tight-bbox finiteness.
2 parents b87182d + cfb0c5b commit a33422b
Copy full SHA for a33422b

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
@@ -1149,21 +1149,17 @@ def get_tightbbox(self, renderer):
11491149
self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2)
11501150
self.offsetText.set_text(self.major.formatter.get_offset())
11511151

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

0 commit comments

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