@@ -4284,6 +4284,7 @@ def get_default_bbox_extra_artists(self):
4284
4284
"""
4285
4285
4286
4286
artists = self .get_children ()
4287
+
4287
4288
if not (self .axison and self ._frameon ):
4288
4289
# don't do bbox on spines if frame not on.
4289
4290
for spine in self .spines .values ():
@@ -4358,7 +4359,8 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4358
4359
bb .append (bb_yaxis )
4359
4360
4360
4361
self ._update_title_position (renderer )
4361
- bb .append (self .get_window_extent (renderer ))
4362
+ axbbox = self .get_window_extent (renderer )
4363
+ bb .append (axbbox )
4362
4364
4363
4365
self ._update_title_position (renderer )
4364
4366
if self .title .get_visible ():
@@ -4375,12 +4377,22 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4375
4377
bbox_artists = self .get_default_bbox_extra_artists ()
4376
4378
4377
4379
for a in bbox_artists :
4380
+ # Extra check here to quickly see if clipping is on and
4381
+ # contained in the axes. If it is, don't get the tightbbox for
4382
+ # this artist because this can be expensive:
4383
+ clip_extent = a ._get_clipping_extent_bbox ()
4384
+ if clip_extent is not None :
4385
+ clip_extent = mtransforms .Bbox .intersection (clip_extent ,
4386
+ axbbox )
4387
+ if np .all (clip_extent .extents == axbbox .extents ):
4388
+ # clip extent is inside the axes bbox so don't check
4389
+ # this artist
4390
+ continue
4378
4391
bbox = a .get_tightbbox (renderer )
4379
4392
if (bbox is not None
4380
4393
and 0 < bbox .width < np .inf
4381
4394
and 0 < bbox .height < np .inf ):
4382
4395
bb .append (bbox )
4383
-
4384
4396
_bbox = mtransforms .Bbox .union (
4385
4397
[b for b in bb if b .width != 0 or b .height != 0 ])
4386
4398
0 commit comments