Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: CL avoid fully collapsed axes #11627

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
tacaswell merged 1 commit into matplotlib:master from jklymak:fix-bad-title-CL-interaction
Jul 15, 2018

Conversation

Copy link
Member

@jklymak jklymak commented Jul 11, 2018
edited
Loading

PR Summary

Applying zoom to an axes with constrained_layout caused problems because the bounding box for a line on the axes was not correctly calculated when constrained_layout needed it to be. That could lead to a collapsed axes, and singular matrices for other transformations.

This PR doesn't fix the underlying problem with the zoom not setting the transform quick enough, but since layout probably doesn't need to change much under zoom, that's likely OK. However, it does stop constrained layout from being applied if any of the axes have zero width or height.

Note this was not a problem before #10682, because now ax.get_tightbbox checks all the artists in the axes.

The only drawback I can see is if someone deliberately had a zero-width/height axes on their figure. But I don't think constrained_layout would work well in that case anyways.

UPDATE: Per @efiring suggestion, I've also turned constrained_layout off if 'PAN' or 'ZOOM' are active. I think this is much safer.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak added this to the v3.0 milestone Jul 11, 2018
@jklymak jklymak added topic: geometry manager LayoutEngine, Constrained layout, Tight layout Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Jul 11, 2018
Copy link
Member Author

jklymak commented Jul 11, 2018

This is minor, and a safety catch, so marking RC for 3.0....

Copy link
Member

efiring commented Jul 12, 2018

Would it make sense, and be reasonably easy, to disable the bbox and constraint calculations when zoom-to-rect or zoom/pan are on?

Copy link
Member Author

jklymak commented Jul 12, 2018
edited
Loading

Yeah if there is a method to detect that’s what the redraw is for, I think that’d be the safest thing most of the time. Is it easy to know that the redraw was triggered for that reason?

EDIT: done - easier than I though...

@@ -199,15 +207,27 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,

fig._layoutbox.constrained_layout_called += 1
fig._layoutbox.update_variables()
# Now set the position of the axes...
# check if layout worked. If not, don't change positions:
Copy link
Member

Choose a reason for hiding this comment

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

You could move this whole check to a local function layout_is_valid(fig) and then just:

if layout_is_valid(fig):
 # Now set the position of the axes...
 ...

or even with a second function apply_layout(fig)

if layout_is_valid(fig):
 apply_layout(fig):
else:
 warnings.warn(...)

I think this would help keeping an overview what's going on.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this is a taste thing. 6 lines is kind of under my "move to its own function" threshold. When debugging I find it pretty annoying to have to chase down chains of three-line rabbit holes that do something trivial.

Copy link
Member

Choose a reason for hiding this comment

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

You are height that this is a matter of taste

My rule of thumb is: A couple of lines that have a distinguished purpose usually make up a good function. Even more so, if I need a comment to explain what they are doing. The function name can often replace the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well thats fair 😉...

Copy link
Member Author

Choose a reason for hiding this comment

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

... done - agree that is a bit nicer...

Copy link
Member

Choose a reason for hiding this comment

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

😄 👍

@jklymak jklymak force-pushed the fix-bad-title-CL-interaction branch from 7034418 to 362c34c Compare July 14, 2018 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@timhoffm timhoffm timhoffm approved these changes

Assignees
No one assigned
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Milestone
v3.0.0
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /