Skip to content

Navigation Menu

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 padding, spacing, and alignment of labels etc for GridSpecFromSubplotSpec with layout="constrained" #28903

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 7 commits into
base: main
Choose a base branch
Loading
from

Conversation

jakelevi1996
Copy link

PR summary

Alternative solution to the issues addressed in PR #28895 , which additionally matches alignment of axis labels, axis tick labels etc for nested grids. Closes #28891 and #28894 . Below is an example of outputs created with this fix applied compared to the same code run with matplotlib 3.9.2. See linked issues and PR for further discussion.

With fix (this PR):

image

matplotlib 3.9.2:

image

PR checklist

@jklymak
Copy link
Member

jklymak commented Sep 28, 2024

OK, you are proposing a different decision metric for what constrained layout is trying to do. I understand that you want the grids to line up as much as possible, even between sub-gridspecs.

However, currently constrained layout tries to maximize the size of axes within their sub-gridspec at the expense of inter-subgridspec alignment. It was designed such that if two different sets of axes are in different sub gridspecs, they are considered independently, with the belief that if they are not in the same subgridspec, then there is no good reason for the axes to line up with each other because they are presumably different data/visualization types. Indeed, I often go out of my way to make axes not line up when I have two subplots with different visualizations so the eye doesn't try to line them up accidentally. This independence also favours maximizing the size of the axes, and hence enlarging the data presentation.

So while I appreciate what you are trying to do here, I don't consider the current behaviour a bug, and I'm not convinced the change is practically better.

@jakelevi1996
Copy link
Author

I'm sorry but I don't understand the criterion. You mentioned in my previous merge request "If the outer container also has a margin that should be respected as well." But in the current implementation (3.9.2), subgrids don't respect the margins of their outer containers (see images above), which makes it impossible to add spaces between different subgrids (which is the use case I care about - I want to do something like the image below, and it seems to me like a bug that this doesn't work in 3.9.2).

image

FYI My ultimate goal here was just to allow spacing between different subgrids (which is not preserved in 3.9.2), which I mentioned in #28891 . As I mentioned in that issue, a one-line solution to allowing space between subgrids (without necessarily aligning axes in different subgrids) was just to include parent_inner=True in layoutgrids[rep] = mlayoutgrid.LayoutGrid(...) in https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/_constrained_layout.py#L226 (not changing default behaviour for anything other than GridSpecFromSubplotSpec). All the other stuff I just did because I thought it would be nicer if axes lined up - but honestly I could happily forget about lining up axes and just add the parent_inner=True solution to allow spacing between subgrids (which is all I want 😢 ).

@jklymak
Copy link
Member

jklymak commented Sep 28, 2024

As I mentioned in that issue, a one-line solution to allowing space between subgrids (without necessarily aligning axes in different subgrids) was just to include parent_inner=True in layoutgrids[rep] = mlayoutgrid.LayoutGrid(...)

I don't think I objected to that one-line solution. I apologize if it seemed I did. I was concerned about the other work that removed the outer margin.

If it were me, I'd put in the change with the one-line solution, let's see what breaks. If after that you want to propose further changes, we can see where that goes.

@jakelevi1996
Copy link
Author

Sounds like a good plan. I have a few other things I need to focus on first, but will hopefully get round to opening a PR for the 1-line solution end of this week/beginning of next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs rebase topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[Bug]: GridSpecFromSubplotSpec displayed incorrectly with layout="constrained"
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.