Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]])

Expand Down Expand Up @@ -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():
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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