diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 1b9859eee3a4..f3d7c14f57f6 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -4172,7 +4172,18 @@ def get_default_bbox_extra_artists(self): Artists are excluded either by not being visible or ``artist.set_in_layout(False)``. """ - return [artist for artist in self.get_children() + + artists = self.get_children() + if not (self.axison and self._frameon): + # don't do bbox on spines if frame not on. + for spine in self.spines.values(): + artists.remove(spine) + + if not self.axison: + for _axis in self._get_axis_list(): + artists.remove(_axis) + + return [artist for artist in artists if (artist.get_visible() and artist.get_in_layout())] def get_tightbbox(self, renderer, call_axes_locator=True, diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index bd4247c6015c..0a8103287110 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -126,6 +126,11 @@ def __init__( self.figure.add_axes(self) + # mplot3d currently manages its own spines and needs these turned off + # for bounding box calculations + for k in self.spines.keys(): + self.spines[k].set_visible(False) + def set_axis_off(self): self._axis3don = False self.stale = True