Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Apr 16, 2018

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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@jklymak jklymak added this to the v2.2.3 milestone Apr 16, 2018
@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Apr 16, 2018
@@ -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
Copy link
Member Author

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

Copy link
Member

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):
Copy link
Member

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.

Copy link
Member Author

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...

@jklymak jklymak force-pushed the fix-call-constrained-layout-twice branch 2 times, most recently from f7cbc2e to e21839d Compare April 17, 2018 18:11
@jklymak
Copy link
Member Author

jklymak commented Apr 17, 2018

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.

Copy link
Member

@timhoffm timhoffm left a 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.

@jklymak
Copy link
Member Author

jklymak commented Apr 18, 2018

@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 😉

@jklymak jklymak force-pushed the fix-call-constrained-layout-twice branch from e21839d to 8ae8ce0 Compare April 18, 2018 17:02
@jklymak
Copy link
Member Author

jklymak commented Apr 18, 2018

...privatized

(widthC*1.8))


def _arange_subplotspecs(gs, hspace=0, wspace=0):
Copy link
Member

Choose a reason for hiding this comment

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

Typo. Probably "arrange" meant.

@jklymak jklymak closed this Apr 18, 2018
@jklymak jklymak force-pushed the fix-call-constrained-layout-twice branch from 8ae8ce0 to 304154c Compare April 18, 2018 23:57
@jklymak jklymak reopened this Apr 19, 2018
@jklymak jklymak force-pushed the fix-call-constrained-layout-twice branch from 8ae8ce0 to 5dfab73 Compare April 19, 2018 00:04
@jklymak
Copy link
Member Author

jklymak commented Apr 19, 2018

Spelling error fixed....

@jklymak jklymak force-pushed the fix-call-constrained-layout-twice branch from 5dfab73 to dad0da1 Compare May 15, 2018 17:21
# fill in any empty gridspec slots w/ ghost axes...
_make_ghost_gridspec_slots(fig, gs)

for nnn in range(2):
Copy link
Member Author

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...

@jklymak
Copy link
Member Author

jklymak commented May 15, 2018

ping @efiring; this is rebased now per this weeks call...

@efiring efiring merged commit bf2b799 into matplotlib:master May 16, 2018
@lumberbot-app
Copy link

lumberbot-app bot commented May 16, 2018

There seem to be a conflict, please backport manually

@dstansby
Copy link
Member

Does this still want a backport to 2.2.x?

@jklymak
Copy link
Member Author

jklymak commented May 29, 2018

Nah its fine...

@jklymak jklymak deleted the fix-call-constrained-layout-twice branch May 29, 2018 13:47
@jklymak jklymak modified the milestones: v2.2.3, v3.0 May 29, 2018
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
None yet
Development

Successfully merging this pull request may close these issues.

4 participants