-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: make subplot reuse gridspecs if they fit #11441
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
Conversation
866a194
to
6ccc62a
Compare
6ccc62a
to
f15a7c7
Compare
I suppose this is a breaking change if someone was checking the results of ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 1, 1)
print(ax2.get_geometry()) used to return |
Perhaps a better idea would be to just always create a new gridspec with shape (lcm(gs1.nrows, gs2.nrows), lcm(gs1.ncols, gs2.ncols)) and reparent all axes to this gridspec? This would avoid the order dependency. |
Yes, that could work. Wasn't 100% sure this whole PR was a good idea, rather than just telling people to not use |
I'm not really sure it's worth it either (well I don't think the implementation would be that complex), just pointing out the possibility. |
Taking this up again in a simpler form in #17347 |
PR Summary
Right now, if we call
The gridspecs will be different. Thats unfortunate, because there is no reason for these two subplots to not share the same gridspec, and if they do, then constrained_layout will work with them. Note this change will mean that many calls to
pyplot.subplot
andpyplot.subplot2grid
will now work withconstrained_layout=True
as well.This PR changes that so they two subplots use the same gridspec.
Note The more fine-grained subplot call must come first, or the grid specs will not "fit", so this is pretty simple minded. However, the PR doesn't make things worse, it just makes two gridspecs like it did before. i.e. if we switch the order of the calls we get two gridspecs:
PR Checklist