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 1c62bb7

Browse filesBrowse files
authored
Merge pull request #14504 from meeseeksmachine/auto-backport-of-pr-14445-on-v3.1.x
Backport PR #14445 on branch v3.1.x (FIX: fastpath clipped artists)
2 parents 1c314c6 + be393c5 commit 1c62bb7
Copy full SHA for 1c62bb7

File tree

Expand file treeCollapse file tree

2 files changed

+31
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-2
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ def get_window_extent(self, renderer):
249249
"""
250250
return Bbox([[0, 0], [0, 0]])
251251

252+
def _get_clipping_extent_bbox(self):
253+
"""
254+
Return a bbox with the extents of the intersection of the clip_path
255+
and clip_box for this artist, or None if both of these are
256+
None, or ``get_clip_on`` is False.
257+
"""
258+
bbox = None
259+
if self.get_clip_on():
260+
clip_box = self.get_clip_box()
261+
if clip_box is not None:
262+
bbox = clip_box
263+
clip_path = self.get_clip_path()
264+
if clip_path is not None and bbox is not None:
265+
clip_path = clip_path.get_fully_transformed_path()
266+
bbox = Bbox.intersection(bbox, clip_path.get_extents())
267+
return bbox
268+
252269
def get_tightbbox(self, renderer):
253270
"""
254271
Like `Artist.get_window_extent`, but includes any clipping.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,6 +4282,7 @@ def get_default_bbox_extra_artists(self):
42824282
"""
42834283

42844284
artists = self.get_children()
4285+
42854286
if not (self.axison and self._frameon):
42864287
# don't do bbox on spines if frame not on.
42874288
for spine in self.spines.values():
@@ -4356,7 +4357,8 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
43564357
bb.append(bb_yaxis)
43574358

43584359
self._update_title_position(renderer)
4359-
bb.append(self.get_window_extent(renderer))
4360+
axbbox = self.get_window_extent(renderer)
4361+
bb.append(axbbox)
43604362

43614363
self._update_title_position(renderer)
43624364
if self.title.get_visible():
@@ -4373,12 +4375,22 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
43734375
bbox_artists = self.get_default_bbox_extra_artists()
43744376

43754377
for a in bbox_artists:
4378+
# Extra check here to quickly see if clipping is on and
4379+
# contained in the axes. If it is, don't get the tightbbox for
4380+
# this artist because this can be expensive:
4381+
clip_extent = a._get_clipping_extent_bbox()
4382+
if clip_extent is not None:
4383+
clip_extent = mtransforms.Bbox.intersection(clip_extent,
4384+
axbbox)
4385+
if np.all(clip_extent.extents == axbbox.extents):
4386+
# clip extent is inside the axes bbox so don't check
4387+
# this artist
4388+
continue
43764389
bbox = a.get_tightbbox(renderer)
43774390
if (bbox is not None
43784391
and 0 < bbox.width < np.inf
43794392
and 0 < bbox.height < np.inf):
43804393
bb.append(bbox)
4381-
43824394
_bbox = mtransforms.Bbox.union(
43834395
[b for b in bb if b.width != 0 or b.height != 0])
43844396

0 commit comments

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