Movatterモバイル変換


[0]ホーム

URL:


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

BUG: Warn when an existing layout manager changes to tight layout#24528

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dstansby merged 1 commit intomatplotlib:mainfromj1642:warn-if-tight-layout
Dec 7, 2022

Conversation

@j1642
Copy link
Contributor

PR Summary

Warn the user with aUserWarning when a figure's layout changes from 'constrained' or 'compressed' to 'tight.'

Addresses#24387

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (andpytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@oscargusoscargus added the topic: geometry managerLayoutEngine, Constrained layout, Tight layout labelNov 21, 2022
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
fig.set_layout_engine("tight")
withpytest.warns(UserWarning):
fig.set_layout_engine("tight")
Copy link
Member

Choose a reason for hiding this comment

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

I find it odd that it both warns and then errors (the error means itdoesn't change, and thus the warning is incorrect)

Consider moving the check up the call stack one level toset_layout_engine such that only one of the error or warning occur.


ifself._check_layout_engines_compat(self._layout_engine,
new_layout_engine):
ifisinstance(self._layout_engine,ConstrainedLayoutEngine) \
Copy link
Member

Choose a reason for hiding this comment

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

I think this is over-reach here. People are allowed to change layout engines.

The problem is if people have set the layout engine and then specifically callplt.tight_layout, usually because they are copying and pasting magic commands, and then wonder why constrained layout got clobbered. This check should be in thetight_layout method, not every time the user uses the API to switch the engine.

I'm not sure what@ksunden was referring to wrt to an error - it is very possible to call tight_layout without an error, so maybe the test was malformed.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

That makes sense, thank you.

Regarding the error, there was a possibility of a newUserWarning immediately followed by aRuntimeError fromfigure.set_layout_engine.

Copy link
Member

Choose a reason for hiding this comment

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

I was referring to a specific test that was included which had both a warning and an error with pytest checks for both. However in the event an error gets raised, the warning is pointless as that means the layout does not get changed.

I agree that I'm not sure it should warn quite so eagerly, but honestly not convinced it should warn fortight_layout either... that seems like a pretty explicit "I want a tight layout" call, so not sure why we are looking to warn that it is doing exactly what is asked.

It feels like that is just as likely to warn users who expect it than it does to catch users who don't expect that behavior.

Copy link
Member

Choose a reason for hiding this comment

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

but honestly not convinced it should warn for tight_layout either... that seems like a pretty explicit "I want a tight layout" call, so not sure why we are looking to warn that it is doing exactly what is asked.

If someone at the top of the code saysplt.figure(layout='constrained') and then at the bottom of the code saysplt.tight_layout() I think it is likely they have made a mistake.

@tacaswelltacaswell added this to thev3.7.0 milestoneDec 6, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jklymakjklymakjklymak left review comments

@ksundenksundenksunden left review comments

@dstansbydstansbydstansby approved these changes

@oscargusoscargusoscargus approved these changes

Assignees

No one assigned

Labels

topic: geometry managerLayoutEngine, Constrained layout, Tight layout

Projects

None yet

Milestone

v3.7.0

Development

Successfully merging this pull request may close these issues.

6 participants

@j1642@jklymak@ksunden@dstansby@oscargus@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp