1212import numpy as np
1313
1414import matplotlib as mpl
15- from matplotlib import _api , cbook , docstring
15+ from matplotlib import _api , cbook , docstring , offsetbox
1616import matplotlib .artist as martist
1717import matplotlib .axis as maxis
1818from matplotlib .cbook import _OrderedSet , _check_1d , index_of
@@ -4541,21 +4541,26 @@ def get_default_bbox_extra_artists(self):
45414541
45424542 artists = self .get_children ()
45434543
4544+ for _axis in self ._get_axis_list ():
4545+ # axis tight bboxes are calculated separately inside
4546+ # Axes.get_tightbbox() using for_layout_only=True
4547+ artists .remove (_axis )
45444548 if not (self .axison and self ._frameon ):
45454549 # don't do bbox on spines if frame not on.
45464550 for spine in self .spines .values ():
45474551 artists .remove (spine )
45484552
4549- if not self .axison :
4550- for _axis in self ._get_axis_list ():
4551- artists .remove (_axis )
4552-
45534553 artists .remove (self .title )
45544554 artists .remove (self ._left_title )
45554555 artists .remove (self ._right_title )
45564556
4557- return [artist for artist in artists
4558- if (artist .get_visible () and artist .get_in_layout ())]
4557+ # always include types that do not internally implement clipping
4558+ # to axes. may have clip_on set to True and clip_box equivalent
4559+ # to ax.bbox but then ignore these properties during draws.
4560+ noclip = (_AxesBase , maxis .Axis ,
4561+ offsetbox .AnnotationBbox , offsetbox .OffsetBox )
4562+ return [a for a in artists if a .get_visible () and a .get_in_layout ()
4563+ and (isinstance (a , noclip ) or not a ._fully_clipped_to_axes ())]
45594564
45604565 def get_tightbbox (self , renderer , call_axes_locator = True ,
45614566 bbox_extra_artists = None , * , for_layout_only = False ):
@@ -4612,17 +4617,11 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
46124617 else :
46134618 self .apply_aspect ()
46144619
4615- if self .axison :
4616- if self .xaxis .get_visible ():
4617- bb_xaxis = martist ._get_tightbbox_for_layout_only (
4618- self .xaxis , renderer )
4619- if bb_xaxis :
4620- bb .append (bb_xaxis )
4621- if self .yaxis .get_visible ():
4622- bb_yaxis = martist ._get_tightbbox_for_layout_only (
4623- self .yaxis , renderer )
4624- if bb_yaxis :
4625- bb .append (bb_yaxis )
4620+ for axis in self ._get_axis_list ():
4621+ if self .axison and axis .get_visible ():
4622+ ba = martist ._get_tightbbox_for_layout_only (axis , renderer )
4623+ if ba :
4624+ bb .append (ba )
46264625 self ._update_title_position (renderer )
46274626 axbbox = self .get_window_extent (renderer )
46284627 bb .append (axbbox )
@@ -4643,17 +4642,6 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
46434642 bbox_artists = self .get_default_bbox_extra_artists ()
46444643
46454644 for a in bbox_artists :
4646- # Extra check here to quickly see if clipping is on and
4647- # contained in the Axes. If it is, don't get the tightbbox for
4648- # this artist because this can be expensive:
4649- clip_extent = a ._get_clipping_extent_bbox ()
4650- if clip_extent is not None :
4651- clip_extent = mtransforms .Bbox .intersection (
4652- clip_extent , axbbox )
4653- if np .all (clip_extent .extents == axbbox .extents ):
4654- # clip extent is inside the Axes bbox so don't check
4655- # this artist
4656- continue
46574645 bbox = a .get_tightbbox (renderer )
46584646 if (bbox is not None
46594647 and 0 < bbox .width < np .inf
0 commit comments