Skip to content

FIX: Don't apply tight_layout if axes collapse #12285

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 Sep 25, 2018

PR Summary

Partially addresses #12256

If tight_layout is called and there is an annotation or legend that is outside the axes, it can sometimes happen that the axes completely collapses. There is currently a warning, but this PR also doesn't apply tight_layout if that happens, under the assumption its better to draw something rather than draw something that is completely broken.

Note however, it is still possible for the axes to get quite small.

The origin of these issues is that axes.get_tightbbox now includes all artists when computing the bounding box, whereas before 3.0 it only included the axes elements themselves, and none of the artists. Now artists can be excluded by explictly setting a.set_inlayout(False).

NOTE: this is an API change in that tight_layout.auto_adjust_subplotpars now can return None if no good subplotpars were computed.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • Documentation is sphinx and numpydoc compliant
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak added this to the v3.0.x milestone Sep 25, 2018
@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Sep 25, 2018
@tacaswell
Copy link
Member

NOTE: this is an API change in that tight_layout.auto_adjust_subplotpars now can return None if no good subplotpars were computed.

Can you document that as an API change? Put it directly in api_changes.rst (rather than a separate file to make the backport easier)

@jklymak
Copy link
Member Author

jklymak commented Sep 27, 2018

@tacaswell Yes, marked WIP now - it should get a test as well.. Done...

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.

Please document that get_tight_layout_figure() can now return None as well.

@jklymak
Copy link
Member Author

jklymak commented Oct 14, 2018

@timhoffm - is the new commit what you were after? Thanks!

@timhoffm
Copy link
Member

timhoffm commented Oct 14, 2018

Flake8 says

./lib/matplotlib/tight_layout.py:298:56: W291 trailing whitespace

@jklymak
Copy link
Member Author

jklymak commented Oct 15, 2018

Thanks! Evil trailing space eradicated....

@jklymak jklymak force-pushed the fix-dont-apply-tight-layout-if-collapsed branch from a250c85 to a58ce76 Compare October 15, 2018 22:41
@tacaswell tacaswell merged commit cfc01ce into matplotlib:master Oct 25, 2018
@tacaswell
Copy link
Member

Thanks @jklymak ! Your work to make sure the tight/constrained layout works well is greatly appreciated!

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.

3 participants