Skip to content

Fix padding and spacing for GridSpecFromSubplotSpec with layout="constrained" #28895

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
from

Conversation

jakelevi1996
Copy link

PR summary

Fix padding and spacing for GridSpecFromSubplotSpec with layout="constrained":

The issues linked above contain images of the problems before and after the fix in this PR is applied.

I marked "new and changed code is tested" as "N/A" because I had an error setting up the development environment. But I have tested my fixes by modifying my matplotlib installation in site-packages (sorry, I know). This is my first time submitting a PR, so I'm guessing the tests will run automatically after I submit the PR, or maybe someone nice is willing to pull my branch and check they pass.

PR checklist

@github-actions github-actions bot added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Sep 26, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@@ -325,6 +327,17 @@ def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
'bottomcb': h_pad, 'topcb': h_pad,
'left': 0, 'right': 0,
'top': 0, 'bottom': 0}

if isinstance(gs, mgridspec.GridSpecFromSubplotSpec):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the issue, I'm not in favour of this change. margins are to be relative to their outer container. If the outer container also has a margin that should be respected as well.

I understand aesthetically what you are trying to do. However, you are basically overriding the point of a margin, which other users may have set this way on purpose. Secondly, in a practical example with labels these axes will almost certainly not be lined up the way you are suggesting anyways.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've come up with an alternative solution to (hopefully) address these issues and opened a new PR: #28903

See images in that PR which demonstrate testing with randomly sized labels, both before and after the new fix is applied.

example_plot(ax, fontsize=9)
axs = []
for gs in gsl0:
ax = fig.add_subplot(gs)
axs += [ax]
pcm = example_pcolor(ax, fontsize=9)
fig.colorbar(pcm, ax=axs, shrink=0.6, aspect=70.)
ax = fig.add_subplot(gsl[0])
ax = fig.add_subplot(inner_sp(gsl[0]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge breaking change. We can't force users to do this!

Comment on lines +741 to +742
axis.get_xaxis().set_visible(False)
axis.get_yaxis().set_visible(False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of constrained_layout is to deal with varying sized labels on axes. You should not remove the tick labels. Ideally you would also test with randomly sized labels, so in this case the inner labels could be shorter than the outer labels.

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
Status: Waiting for author
2 participants