-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
base: main
Are you sure you want to change the base?
Fix padding and spacing for GridSpecFromSubplotSpec
with layout="constrained"
#28895
Conversation
…not double counted
There was a problem hiding this 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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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])) |
There was a problem hiding this comment.
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!
axis.get_xaxis().set_visible(False) | ||
axis.get_yaxis().set_visible(False) |
There was a problem hiding this comment.
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.
PR summary
Fix padding and spacing for
GridSpecFromSubplotSpec
withlayout="constrained"
:GridSpecFromSubplotSpec
displayed incorrectly withlayout="constrained"
#28891 , in which the elements of aGridSpecFromSubplotSpec
overlap theSubplotSpec
that they belong to (EG so spacing between differentGridSpecFromSubplotSpec
instances isn't displayed properly)GridSpecFromSubplotSpec
is double counted withlayout="constrained"
#28894 , in which unnecessary additional padding is added to the outer elements of aGridSpecFromSubplotSpec
instanceThe 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 insite-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