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 contrained layout applying pad multiple times#30108

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

Open
rcomer wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromrcomer:submerged-margins

Conversation

rcomer
Copy link
Member

PR summary

Discovered when I was trying to wrap my head around#30089. Given

importmatplotlib.pyplotaspltmosaic1="AC;BC"mosaic2="ACDE;BCDE"formosaicinmosaic1,mosaic2:fig,ax_dir=plt.subplot_mosaic(mosaic,layout='constrained',facecolor='skyblue')fig.get_layout_engine().set(h_pad=0.2)plt.show()

Onmain, the gap between the rows of the first column is larger when there are more other columns

image
image

Currently the "submerged margins" function works out the required size of the margin by summing the main margin and the "cb" margin (which includes our initial pad). If I have understood, we then apply that required size to only the main margin. So the "cb" margin size gets added on each time we pass through the loop.

Here I just subtract the "cb" values we started with from the target margin size. So the total margin should be what we are aiming for. So the above code now gives:

image
image

Given that some test images changed, I'm unsure if this would count as an API change.

PR checklist

@github-actionsgithub-actionsbot added the topic: geometry managerLayoutEngine, Constrained layout, Tight layout labelMay 25, 2025
@jklymak
Copy link
Member

This seems OK. However, can we make sure it works when there actually is a colorbar? (cb is shorthand for the colorbar margins)

@rcomer
Copy link
MemberAuthor

rcomer commentedMay 25, 2025
edited
Loading

Something like this?

importmatplotlib.pyplotaspltmosaic="AABBCC;DDDEEE"fig,ax_dir=plt.subplot_mosaic(mosaic,layout='constrained',facecolor='skyblue')cf=ax_dir['A'].contourf([[0,1], [2,3]])fig.colorbar(cf)plt.show()

image

@jklymak
Copy link
Member

Hmm, if I dont' have the submerged axes then I get
Figure_1

But I guess we want the middle axes centred on the bottom two and the same size as the two to the right, so maybe this PR good?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
topic: geometry managerLayoutEngine, Constrained layout, Tight layout
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@rcomer@jklymak

[8]ページ先頭

©2009-2025 Movatter.jp