@@ -4292,6 +4292,7 @@ def get_default_bbox_extra_artists(self):
4292
4292
"""
4293
4293
4294
4294
artists = self .get_children ()
4295
+
4295
4296
if not (self .axison and self ._frameon ):
4296
4297
# don't do bbox on spines if frame not on.
4297
4298
for spine in self .spines .values ():
@@ -4366,7 +4367,8 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4366
4367
bb .append (bb_yaxis )
4367
4368
4368
4369
self ._update_title_position (renderer )
4369
- bb .append (self .get_window_extent (renderer ))
4370
+ axbbox = self .get_window_extent (renderer )
4371
+ bb .append (axbbox )
4370
4372
4371
4373
self ._update_title_position (renderer )
4372
4374
if self .title .get_visible ():
@@ -4383,12 +4385,20 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4383
4385
bbox_artists = self .get_default_bbox_extra_artists ()
4384
4386
4385
4387
for a in bbox_artists :
4388
+ # Extra check here to quickly see if clipping is on and
4389
+ # contained in the axes. If it is, don't get the tightbbox for
4390
+ # this artist because this can be expensive:
4391
+ clip_extent = a ._get_clipping_extent_bbox ()
4392
+ if clip_extent is not None :
4393
+ clip_extent = mtransforms .Bbox .intersection (clip_extent ,
4394
+ axbbox )
4395
+ if np .all (clip_extent .extents == axbbox .extents ):
4396
+ continue
4386
4397
bbox = a .get_tightbbox (renderer )
4387
4398
if (bbox is not None
4388
4399
and 0 < bbox .width < np .inf
4389
4400
and 0 < bbox .height < np .inf ):
4390
4401
bb .append (bbox )
4391
-
4392
4402
_bbox = mtransforms .Bbox .union (
4393
4403
[b for b in bb if b .width != 0 or b .height != 0 ])
4394
4404
0 commit comments