Include outward ticks in bounding box #5683

Merged
merged 5 commits into from Dec 19, 2015

Conversation

Projects
None yet
4 participants
Owner

mdboom commented Dec 15, 2015

Replaces #5502.

mdboom added the needs_review label Dec 15, 2015

mdboom added some commits Dec 15, 2015

@mdboom mdboom Include outward ticks in bounding box
46ae4d9
@mdboom mdboom Correct comment
62804e8
Owner

mdboom commented Dec 15, 2015

This needs a test specifically of tight layout on outward ticks, but I thought I'd put this up for comment early anyway...

mdboom added this to the next major release (2.0) milestone Dec 15, 2015

Member

QuLogic commented Dec 15, 2015

I think you meant this replaces #5502?

Owner

mdboom commented Dec 15, 2015

I think you meant this replaces #5502?

Oops. You're right.

Member

QuLogic commented Dec 15, 2015

Well, I don't see anything particularly wrong with it, but are there no test images that use outward ticks? Or just none with a tight bounding box?

Owner

mdboom commented Dec 16, 2015

A test has been added

@WeatherGod WeatherGod commented on the diff Dec 16, 2015

lib/matplotlib/axes/_base.py
@@ -567,7 +567,11 @@ def get_window_extent(self, *args, **kwargs):
get the axes bounding box in display space; *args* and
*kwargs* are empty
"""
- return self.bbox
+ 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]])
@WeatherGod

WeatherGod Dec 16, 2015

Member

Is this going to work for polar axes? I would also double-check that this doesn't utterly bork for axes3d (not that I'd expect it to work great there, just to not crash or something).

@mdboom

mdboom Dec 16, 2015

Owner

polar axes don't have ticks -- but it does appear that this needs to be updated so it's aware of when the ticks are present or not.

It doesn't seem to crash for axes3d, though as you say, it doesn't really do the right thin other than add a bit more space.

Member

WeatherGod commented Dec 16, 2015

image tests that have just been added are failing

Member

WeatherGod commented Dec 16, 2015

I don't think the test is really all that useful. tight_layout is for ensuring that subplots don't run into each other. So, a good test would be to have a grid of subplots, perhaps each with different tick directions?

Owner

mdboom commented Dec 17, 2015

@WeatherGod: I've updated the test as you helpfully suggested.

@tacaswell tacaswell and 1 other commented on an outdated diff Dec 17, 2015

lib/matplotlib/axis.py
@@ -169,6 +169,21 @@ def apply_tickdir(self, tickdir):
"""
pass
+ def get_tickdir(self):
+ return self._tickdir
+
+ def get_tick_padding(self):
+ """
+ Get the length of the tick outside of the axes.
+ """
+ tickdir = self._tickdir
+ if tickdir == 'in':
@tacaswell

tacaswell Dec 17, 2015

Owner

bit of a bike shed, better to do this with a dictionary?

@tacaswell tacaswell and 2 others commented on an outdated diff Dec 17, 2015

lib/matplotlib/axis.py
@@ -1097,6 +1108,9 @@ def get_tightbbox(self, renderer):
else:
return None
+ def get_tick_padding(self):
+ return self.majorTicks[0].get_tick_padding()
@tacaswell

tacaswell Dec 17, 2015

Owner

should this be max(self.majorTicks[0].get_tick_padding(), self.minorTicks[0].get_tick_padding())) ?

Never underestimate pathological users....

@mdboom

mdboom Dec 17, 2015

Owner

That's a good point.

@WeatherGod

WeatherGod Dec 17, 2015

Member

Another point: are we always guaranteed at least one tick?

On Thu, Dec 17, 2015 at 11:59 AM, Michael Droettboom <
notifications@github.com> wrote:

In lib/matplotlib/axis.py
#5683 (comment):

@@ -1097,6 +1108,9 @@ def get_tightbbox(self, renderer):
else:
return None

  • def get_tick_padding(self):
  •    return self.majorTicks[0].get_tick_padding()
    

That's a good point.


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5683/files#r47930730.

Owner

mdboom commented Dec 17, 2015

I've addressed @tacaswell's comments, and added minor ticks to the test to catch the pathological case he mentions.

Owner

mdboom commented Dec 17, 2015

Also updated to handle the case where there are no ticks, as suggested by @WeatherGod

mdboom added some commits Dec 16, 2015

@mdboom mdboom Add test 0bf73c1
@mdboom mdboom Handle case where there are no ticks
0a4b52e

@tacaswell tacaswell added a commit that referenced this pull request Dec 19, 2015

@tacaswell tacaswell Merge pull request #5683 from mdboom/tight-ticks
Include outward ticks in bounding box
08fc864

@tacaswell tacaswell merged commit 08fc864 into matplotlib:master Dec 19, 2015

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.02%) to 68.303%
Details

tacaswell removed the needs_review label Dec 19, 2015

Owner

tacaswell commented Dec 19, 2015

backported as 2a6bb26

@tacaswell tacaswell added a commit that referenced this pull request Dec 19, 2015

@tacaswell tacaswell Merge pull request #5683 from mdboom/tight-ticks
Include outward ticks in bounding box
2a6bb26

@tacaswell tacaswell added a commit that referenced this pull request Dec 19, 2015

@tacaswell tacaswell Merge pull request #5683 from mdboom/tight-ticks
Include outward ticks in bounding box
8ac5b4b
Member

QuLogic commented Oct 16, 2016

Backport to v2.x was actually via 8ac5b4b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment