-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX constrained_layout w/ hidden axes #14919
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
Conversation
Could easily be back ported if not a bother. |
56ecc84
to
eb410f0
Compare
Forget the above. Yes, this is the correct fix. If you want to not have the axes take part in the layout you should use |
An empty gridspec box gets a placeholder like this anyhow, so this is the smallest box that is possible for this spot if gridspec or I do this because if someone has a gap in their layout presumably they want it to be there. And it is needed to keep the axes in rows above or below a blank (for instance) aligned. This is somewhat poorly documented at: https://matplotlib.org/3.1.1/tutorials/intermediate/constrainedlayout_guide.html#empty-gridspec-slots |
Yes, I realized that 5 minutes after I posted (see edit above), sorry for the confusion. |
Too fast! Though I'll point out that even remove will still put a blank gridspec in there (actually an axes with all the elements made invisible!) |
@@ -272,7 +272,11 @@ def _make_layout_margins(ax, renderer, h_pad, w_pad): | |||
invTransFig = fig.transFigure.inverted().transform_bbox | |||
pos = ax.get_position(original=True) | |||
tightbbox = ax.get_tightbbox(renderer=renderer) | |||
bbox = invTransFig(tightbbox) | |||
if tightbbox is None: |
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.
Just:
bbox = pos if tightbbox is None else invTransFig(tightbbox)
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.
I find those really hard to read a lot of the time.
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.
Actually, when reading a function for a basic understanding what it does I find this more easy.
It's just one line saying: "Sets bbox
depending on some condition". The if/else is already more low level.
But not fighting over 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.
👍 with a comment on the test
eb410f0
to
1911cc8
Compare
18538e2
to
47f0128
Compare
flake8:
|
Update lib/matplotlib/tests/test_constrainedlayout.py Co-Authored-By: David Stansby <dstansby@gmail.com> FLAKE8
dc6186f
to
c8ec3c6
Compare
Hmmm, I kept trying to rebase that change in, but I suspect I added the space in the "TST" commit, so it kept overwriting it. Ooops.... |
…919-on-v3.1.x Backport PR #14919 on branch v3.1.x (FIX constrained_layout w/ hidden axes)
PR Summary
If an axes is hidden (set_visible(False)) then it has no tightbbox. But we still need to position it w/
constrained_layout
, pointed out in #14917 (thanks @ImportanceOfBeingErnest )Closes #14918
PR Checklist