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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented May 25, 2025

PR summary

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

import matplotlib.pyplot as plt

mosaic1 = "AC;BC"
mosaic2 = "ACDE;BCDE"

for mosaic in mosaic1, mosaic2:
    fig, ax_dir = plt.subplot_mosaic(mosaic, layout='constrained', facecolor='skyblue')
    fig.get_layout_engine().set(h_pad=0.2)
    
plt.show()

On main, 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-actions github-actions bot added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label May 25, 2025
@jklymak
Copy link
Member

jklymak commented May 25, 2025

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
Member Author

rcomer commented May 25, 2025

Something like this?

import matplotlib.pyplot as plt

mosaic = "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

jklymak commented May 26, 2025

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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.