diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e50e129ecb3e..319479a9af8c 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -583,8 +583,12 @@ def get_window_extent(self, *args, **kwargs): *kwargs* are empty """ bbox = self.bbox - x_pad = self.xaxis.get_tick_padding() - y_pad = self.yaxis.get_tick_padding() + x_pad = 0 + if self.axison and self.xaxis.get_visible(): + x_pad = self.xaxis.get_tick_padding() + y_pad = 0 + if self.axison and self.yaxis.get_visible(): + y_pad = self.yaxis.get_tick_padding() return mtransforms.Bbox([[bbox.x0 - x_pad, bbox.y0 - y_pad], [bbox.x1 + x_pad, bbox.y1 + y_pad]]) @@ -4145,7 +4149,6 @@ def get_tightbbox(self, renderer, call_axes_locator=True): bb.append(bb_xaxis) self._update_title_position(renderer) - bb.append(self.get_window_extent(renderer)) if self.title.get_visible(): diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 7eb273e32e51..652982950818 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5714,3 +5714,15 @@ def test_markerfacecolor_none_alpha(): fig2.savefig(buf2) assert buf1.getvalue() == buf2.getvalue() + + +def test_tick_padding_tightbbox(): + "Test that tick padding gets turned off if axis is off" + plt.rcParams["xtick.direction"] = "out" + plt.rcParams["ytick.direction"] = "out" + fig, ax = plt.subplots() + bb = ax.get_window_extent(fig.canvas.get_renderer()) + ax.axis('off') + bb2 = ax.get_window_extent(fig.canvas.get_renderer()) + assert bb.x0 < bb2.x0 + assert bb.y0 < bb2.y0
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: