21
21
import matplotlib .font_manager as font_manager
22
22
import matplotlib .image as mimage
23
23
import matplotlib .lines as mlines
24
+ from matplotlib .offsetbox import OffsetBox
24
25
import matplotlib .patches as mpatches
25
26
import matplotlib .path as mpath
26
27
from matplotlib .rcsetup import cycler , validate_axisbelow
@@ -4541,21 +4542,25 @@ def get_default_bbox_extra_artists(self):
4541
4542
4542
4543
artists = self .get_children ()
4543
4544
4545
+ for _axis in self ._get_axis_list ():
4546
+ # axis tight bboxes are calculated separately inside
4547
+ # Axes.get_tightbbox() using for_layout_only=True
4548
+ artists .remove (_axis )
4544
4549
if not (self .axison and self ._frameon ):
4545
4550
# don't do bbox on spines if frame not on.
4546
4551
for spine in self .spines .values ():
4547
4552
artists .remove (spine )
4548
4553
4549
- if not self .axison :
4550
- for _axis in self ._get_axis_list ():
4551
- artists .remove (_axis )
4552
-
4553
4554
artists .remove (self .title )
4554
4555
artists .remove (self ._left_title )
4555
4556
artists .remove (self ._right_title )
4556
4557
4557
- return [artist for artist in artists
4558
- if (artist .get_visible () and artist .get_in_layout ())]
4558
+ # always include types that do not internally implement clipping
4559
+ # to axes. may have clip_on set to True and clip_box equivalent
4560
+ # to ax.bbox but then ignore these properties during draw.
4561
+ noclip = (_AxesBase , maxis .Axis , OffsetBox , mtext ._AnnotationBase )
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 ())]
4559
4564
4560
4565
def get_tightbbox (self , renderer , call_axes_locator = True ,
4561
4566
bbox_extra_artists = None , * , for_layout_only = False ):
@@ -4612,17 +4617,11 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4612
4617
else :
4613
4618
self .apply_aspect ()
4614
4619
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 )
4626
4625
self ._update_title_position (renderer )
4627
4626
axbbox = self .get_window_extent (renderer )
4628
4627
bb .append (axbbox )
@@ -4643,17 +4642,6 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4643
4642
bbox_artists = self .get_default_bbox_extra_artists ()
4644
4643
4645
4644
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
4657
4645
bbox = a .get_tightbbox (renderer )
4658
4646
if (bbox is not None
4659
4647
and 0 < bbox .width < np .inf
0 commit comments