Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
anntzer merged 2 commits intomatplotlib:masterfromjklymak:fix-CL-hidden-axes
Aug 12, 2019

Conversation

jklymak
Copy link
Member

@jklymakjklymak commentedJul 30, 2019
edited
Loading

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

importnumpyasnpimportmatplotlib.pyplotaspltfig5,axs=plt.subplots(2,2,constrained_layout=True)axs[0,1].set_visible(False)plt.show()

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymakjklymak added the topic: geometry managerLayoutEngine, Constrained layout, Tight layout labelJul 30, 2019
@jklymakjklymak added this to thev3.1.2 milestoneJul 30, 2019
@jklymak
Copy link
MemberAuthor

Could easily be back ported if not a bother.

@jklymakjklymak mentioned this pull requestJul 30, 2019
5 tasks
@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commentedJul 30, 2019
edited
Loading

Should a non-visible axes take part in the layout? If the answer to that is yes, this is a good fix; but one might also consider that a non-visible axes may just be treated as "not there", or maybe as the most tiny box possible at the center of its original position?

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.remove() instead.

@jklymak
Copy link
MemberAuthor

An empty gridspec box gets a placeholder like this anyhow, so this is the smallest box that is possible for this spot if gridspec orsubplots has been used for the layout.

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
and its checked in one of the tests... (the horribly named:test_constrained_layout8)

@ImportanceOfBeingErnest
Copy link
Member

Yes, I realized that 5 minutes after I posted (see edit above), sorry for the confusion.

jklymak reacted with thumbs up emoji

@jklymak
Copy link
MemberAuthor

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:
Copy link
Member

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)

Copy link
MemberAuthor

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.

Copy link
Member

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: "Setsbbox depending on some condition". The if/else is already more low level.

But not fighting over this.

Copy link
Member

@dstansbydstansby left a 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

@jklymakjklymakforce-pushed thefix-CL-hidden-axes branch 3 times, most recently from18538e2 to47f0128CompareAugust 8, 2019 15:23
@timhoffm
Copy link
Member

flake8:

./lib/matplotlib/_constrained_layout.py:279:1: W293 blank line contains whitespace

Update lib/matplotlib/tests/test_constrainedlayout.pyCo-Authored-By: David Stansby <dstansby@gmail.com>FLAKE8
@jklymak
Copy link
MemberAuthor

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....

@anntzeranntzer merged commit76afe83 intomatplotlib:masterAug 12, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestAug 12, 2019
dstansby added a commit that referenced this pull requestAug 13, 2019
…919-on-v3.1.xBackport PR#14919 on branch v3.1.x (FIX constrained_layout w/ hidden axes)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm left review comments

@dstansbydstansbydstansby approved these changes

@anntzeranntzeranntzer approved these changes

@ImportanceOfBeingErnestImportanceOfBeingErnestImportanceOfBeingErnest approved these changes

Assignees
No one assigned
Labels
topic: geometry managerLayoutEngine, Constrained layout, Tight layout
Projects
None yet
Milestone
v3.1.2
Development

Successfully merging this pull request may close these issues.

constrained_layout fails with hidden axis...
5 participants
@jklymak@ImportanceOfBeingErnest@timhoffm@anntzer@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp