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
FIX: return the actual ax.get_window_extent #12716
Conversation
The x-ticks are still not in? |
oops, sorry, old PNG... |
BTW, I'm open to the ticks not being included in |
Only 4 tests changed because of this! No wonder no one knew... |
just my two cents ... it would be better not to include ticks in |
Or we could move ticks to the axis (vs axes) window extent. Or have a spine extent. |
I think the underlying question is: If you specify
do you then expect the tick ends to be 50 pixels away from the left figure edge or the axes spine? However, for the tight_layout calculations, one would probably not expect to have overlapping ticks. So here the tick ends should be relevant. In total this might make things a bit more complicated?
Isn't that quite worrying? I would expect all image tests to fail. If they don't, it would mean that the tests do not test the actual figures being produced. So is this backend dependent? Or is there an rc setting that steers this? |
This is controlled and set by the Note this is somewhat of an argument against OTOH, adding the extra padding for the ticks in the case where the spines are not in their default location is a bad idea, and indeed I think currently fails....
You need soemthing that cares about the layout for this to be important, e.g. tight_layout, constrained_layout and bbox_inches='tight'. Why most of the tests didn't change is because most of the tests of those functionalities have tick labels, and the ticklabels were setting the outer bounding box of the axes, not the ticks or spines themselves, or in this case, the extent of the axes. So the change is not as intrusive as one would fear. |
adb6a0f
to
e1f6c6f
Compare
Yes, I confused myself. The axes are at the correct positions and it's really |
bb_xaxis = self.xaxis.get_tightbbox(renderer) | ||
if bb_xaxis: | ||
bb.append(bb_xaxis) | ||
if self.axison: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change (self.axison), caused a few tests top change. So this is probably a breaking change. OTOH, I think its correct - it doesn't make sense to include the axis in the tight layout if its been turned off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about if not self.xaxis.get_visible()? (just asking)
👍 in principle. Agree with the behavior changes. |
c4ed807
to
e803350
Compare
7d51709
to
f29d2ae
Compare
I'll ping for reviews on this one.... |
It's not totally clear to me why the tick is part of the spine, but the label is not? |
Well, I'm not proposing to change the existing organization, which I won't pretend to understand. I'm just making |
Right now you changed spine.get_extent to include the ticks; I'm proposing to change axis.get_extent to do that instead. (Following a very cursory read...) |
Can ticks be detached from the spine? I think placing the labels depends on knowing where the spine extent, including ticks, so I can at least see a case for separating these two things. |
Because the standard in Python is to have a test file per module, the problem with the organization of oure tests is actually due to the size of the axes module: it's way too big. We already splitted in two in 2013, and we talked about continuing to refactor it to have smaller size objects and modules but never went forward with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new changes are good. I consider the organisation between get_window_extent and get_tightbbox to be adequate, and it's well documented to avoid future confusion. Technically, it does now return the correct bboxes in the respective cases. Based on that I will approve this.
This is of course modulo the tests passing and coming to a conclusion on where to put the tests (I don't have any opinion on that, but acknowledge that others might)
762d738
to
c7d2c1c
Compare
@jklymak needs another re-base. I think those tests no longer exist? |
c7d2c1c
to
557f099
Compare
Fixed - note the outward ticks test changed a bit, and I restructured it so that I could get the right numbers when the comparison failed. I could put it back, but I actually think this is more readable... |
557f099
to
7d73169
Compare
f548ea0
to
1eb1008
Compare
1eb1008
to
c676f45
Compare
Woops, just accidentally pressed some reveiw request buttons, feel free to ignore... |
The appevyor failure was upload related. |
Something went wrong ... Please have a look at my logs. |
…716-on-v3.1.x Backport PR #12716 on branch v3.1.x (FIX: return the actual ax.get_window_extent)
|
||
See Also | ||
-------- | ||
matplotlib.axis.Axes.get_window_extent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These extra 'See also' sections with non functional API links are breaking more strict docs builds downstream.
https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.axes.Axes.get_tightbbox.html#matplotlib.axes.Axes.get_tightbbox
(We run the docs build in our CI in astropy with the -w
option, so any sphinx warning is causing a failure (as our WCSAxes class is inherited from Axes
and ultimately from this docstring).
If it's helpful I can open a separate issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new issue would get better traction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also run sphinx with -W
in our options
Line 5 in 512aecb
SPHINXOPTS = -W --keep-going |
so it is odd that astropy is failing but we are not...
I suspect difference is sphinx versions (we are currently pinning to sphinx < 2 due to weird spacing at TOC and some breakage (which may be this)).
It is also odd that this is not linking an the 'previous' link in the top right is the thing we want this to have linked to.
Agree with @QuLogic , this should get it's own issue.
PR Summary
Closes #12697
Previously,
ax.get_window_extent()
tried to take into account ticks around the axes. It did this incorrectly because it did not take into account dpi of the canvas, and it just put a pad around the whole axes, without regard for where the ticks actually were.This PR changes
ax.get_window_extent()
so that it does not have a pad around the outside, and hence just returns a bbox that is fit to the size of the axes.It moves the tick padding logic into
spine.get_window_extent()
where it can check tick direction, and pad the spine bbox appropriately.It also fixes
ax.axison
being ignored byax.get_tightbbox
; if the x/yaxis isn't visible, then it should not be part of the tightbbox.Before:
Extents are slightly larger because they are supposed to account for the ticks. But the tick size was not properly scaled into pixels
Now:
More illustrative test
Key:
ax.get_tightbbox()
ax.get_window_extent()
ax.yaxis.get_tightbbox()
,ax.xaxis.get_tightbbox()
,ax.spines.get_window_extent()
.Before
After:
PR Checklist