From 9228c0ff70184c6bdda22a92131441f18a067263 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 9 May 2018 09:45:49 -0700 Subject: [PATCH 1/2] FIX: don't pad axes for ticks if they aren't visible and axis off --- lib/matplotlib/axes/_base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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(): From 1c35254e41aac7b9153ab3abd2d6f651593938b7 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 9 May 2018 10:57:22 -0700 Subject: [PATCH 2/2] TST: test that setting the axis off changes the window_extent of the axes --- lib/matplotlib/tests/test_axes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy