-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: call constrained_layout twice #11062
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
FIX: call constrained_layout twice #11062
Conversation
@@ -202,245 +202,253 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad, | |||
ax.set_yticks([]) | |||
ax.set_facecolor((1, 0, 0, 0)) | |||
|
|||
# for each axes, make a margin between the *pos* layoutbox and the |
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.
Note that the changes here are just an indent and adding a for-loop, so nowhere near as big a deal as this makes it look
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.
Adding ?w=1
to the end of a diff url makes only whitespace changes disappear, which should help reviewing. (https://github.com/matplotlib/matplotlib/pull/11062/files?w=1)
# should be at least twice as large as ax1. | ||
# But it can be more than twice as large because | ||
# it needs less room for the labeling. | ||
for nnn in range(2): |
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.
Please add at least a comment why this is there.
General note on code structure:
The length and nesting level of the function smells liike it would like to be refactored to smaller (private) functions. Then, also the for loop could be replaced with twice a call to a function (e.g. _calc_margins()
- didn't look at the details so the name is probably not good).
Just an observation. Not necessary a call for action.
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.
Agreed; its definitely gotten to that point... I'll refactor as part of this PR...
f7cbc2e
to
e21839d
Compare
OK, made refactor suggested by @timhoffm so now the whitespace changes are even worse, but the algorithm is still exactly the same, except for being called twice. |
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.
Even though, the module itself is private, I'd still suggest to mark the helper functions you created as private as well.
Other than that, it's good enough. More could be done in terms of refactoring and code quality, but let's not overdo it here. If there is interest, we can discuss this separately.
@timhoffm Coding suggestions always gratefully accepted, particularly if they make things more efficient or easier to follow. Happy if you have a few to add now, while the code is being touched, but I would like to get this in semi-soon since there are a few examples that could benefit from the change. If folks make PRs against these modules, I'd like to be involved before they get committed because I would like to be able to debug and fix issues with the modules for the next little while in an expedited manner, and if the code gets full of super-fancy pythonic constructs that may hamper my ability to know whats going on 😉 |
e21839d
to
8ae8ce0
Compare
...privatized |
(widthC*1.8)) | ||
|
||
|
||
def _arange_subplotspecs(gs, hspace=0, wspace=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.
Typo. Probably "arrange" meant.
8ae8ce0
to
304154c
Compare
8ae8ce0
to
5dfab73
Compare
Spelling error fixed.... |
5dfab73
to
dad0da1
Compare
# fill in any empty gridspec slots w/ ghost axes... | ||
_make_ghost_gridspec_slots(fig, gs) | ||
|
||
for nnn in range(2): |
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 the only substantive change in this. The rest is refactor some fo the code into smaller subroutines...
ping @efiring; this is rebased now per this weeks call... |
There seem to be a conflict, please backport manually |
Does this still want a backport to |
Nah its fine... |
PR Summary
There are too many examples popping up where constrained layout needs a second pass to get the layout right. This won't help the performance, but it will be much more likely to be correct...
PR Checklist