@@ -4282,6 +4282,7 @@ def get_default_bbox_extra_artists(self):
4282
4282
"""
4283
4283
4284
4284
artists = self .get_children ()
4285
+
4285
4286
if not (self .axison and self ._frameon ):
4286
4287
# don't do bbox on spines if frame not on.
4287
4288
for spine in self .spines .values ():
@@ -4356,7 +4357,8 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4356
4357
bb .append (bb_yaxis )
4357
4358
4358
4359
self ._update_title_position (renderer )
4359
- bb .append (self .get_window_extent (renderer ))
4360
+ axbbox = self .get_window_extent (renderer )
4361
+ bb .append (axbbox )
4360
4362
4361
4363
self ._update_title_position (renderer )
4362
4364
if self .title .get_visible ():
@@ -4373,12 +4375,22 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4373
4375
bbox_artists = self .get_default_bbox_extra_artists ()
4374
4376
4375
4377
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
4376
4389
bbox = a .get_tightbbox (renderer )
4377
4390
if (bbox is not None
4378
4391
and 0 < bbox .width < np .inf
4379
4392
and 0 < bbox .height < np .inf ):
4380
4393
bb .append (bbox )
4381
-
4382
4394
_bbox = mtransforms .Bbox .union (
4383
4395
[b for b in bb if b .width != 0 or b .height != 0 ])
4384
4396
0 commit comments