Skip to content

FIX: don't pad axes for ticks if they aren't visible or axis off #11210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented May 9, 2018

PR Summary

Since 1.5.3 (two years ago) we added:

def get_window_extent(self, *args, **kwargs):
"""
get the axes bounding box in display space; *args* and
*kwargs* are empty
"""
bbox = self.bbox
x_pad = self.xaxis.get_tick_padding()
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]])

First, this seems like a funny place to put the padding for ticks - I'd have expected it to be in the axis bbox, not the axes bbox. But presumably someone wanted to know the extent of the axes and its ticks w/o knowing the rest of the decorators? The original issues that spurred #5683 seemed to be tight_layout not respecting outward ticks. IMHO this "fix" was wrong and the axis bboxes should include the ticks not the axes, But xaxis.get_tightbbox does not include the ticks even though it controls everything about the ticks.

Second, ax.set_axis_off sets aax.axison=False, but it doesn't change the visibility of the axis, which is still True. I haven't fixed this, but it seems strange to have two flags that control the visibility of an axis.

Anyways, this is an easy fix given how things are now to make the tightbbox actually behave like there are no ticks present.

Closes: #11203

  • Probably needs a good test....
  • Milestoning 3.0 as this regression is very old.
import numpy as np
from matplotlib import pyplot as plt

# axis ticks removed
fig, ax = plt.subplots(figsize=(1,1))
ax.matshow(np.ones((10,10)), cmap=plt.cm.Blues_r, aspect='auto')
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.axis('off')
fig.tight_layout()
fig.savefig('test_noticks.png', dpi=300, bbox_inches='tight', pad_inches=0, facecolor='red')

before

test_noticks

after

test_noticks

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@jklymak jklymak added this to the v3.0 milestone May 9, 2018
@jklymak
Copy link
Member Author

jklymak commented May 9, 2018

test added....

@jklymak jklymak changed the title FIX: don't pad axes for ticks if they aren't visible and axis off FIX: don't pad axes for ticks if they aren't visible or axis off May 9, 2018
@phobson phobson merged commit 6665bc7 into matplotlib:master Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tight_layout reserves tick space even if disabled
3 participants