Skip to content

Commit 6665bc7

Browse files
authored
Merge pull request matplotlib#11210 from jklymak/fix-dont-pad-axes-if-no-axis
FIX: don't pad axes for ticks if they aren't visible or axis off
2 parents bc0882e + 1c35254 commit 6665bc7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,12 @@ def get_window_extent(self, *args, **kwargs):
583583
*kwargs* are empty
584584
"""
585585
bbox = self.bbox
586-
x_pad = self.xaxis.get_tick_padding()
587-
y_pad = self.yaxis.get_tick_padding()
586+
x_pad = 0
587+
if self.axison and self.xaxis.get_visible():
588+
x_pad = self.xaxis.get_tick_padding()
589+
y_pad = 0
590+
if self.axison and self.yaxis.get_visible():
591+
y_pad = self.yaxis.get_tick_padding()
588592
return mtransforms.Bbox([[bbox.x0 - x_pad, bbox.y0 - y_pad],
589593
[bbox.x1 + x_pad, bbox.y1 + y_pad]])
590594

@@ -4136,7 +4140,6 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
41364140
bb.append(bb_xaxis)
41374141

41384142
self._update_title_position(renderer)
4139-
41404143
bb.append(self.get_window_extent(renderer))
41414144

41424145
if self.title.get_visible():

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5714,3 +5714,15 @@ def test_markerfacecolor_none_alpha():
57145714
fig2.savefig(buf2)
57155715

57165716
assert buf1.getvalue() == buf2.getvalue()
5717+
5718+
5719+
def test_tick_padding_tightbbox():
5720+
"Test that tick padding gets turned off if axis is off"
5721+
plt.rcParams["xtick.direction"] = "out"
5722+
plt.rcParams["ytick.direction"] = "out"
5723+
fig, ax = plt.subplots()
5724+
bb = ax.get_window_extent(fig.canvas.get_renderer())
5725+
ax.axis('off')
5726+
bb2 = ax.get_window_extent(fig.canvas.get_renderer())
5727+
assert bb.x0 < bb2.x0
5728+
assert bb.y0 < bb2.y0

0 commit comments

Comments
 (0)