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

FIX: be more careful about not importing pyplot early#17764

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
anntzer merged 1 commit intomatplotlib:masterfromtacaswell:fix_early_use_call
Jun 29, 2020

Conversation

tacaswell
Copy link
Member

PR Summary

In matplotlib.use we import pyplot to useswitch_backend, however
if the user callsmpl.use(...) before importing pyplot then
during the initial import of pyplot, before we set the selected
backend we try to set the backend set via rcParams.

This change only imports pyplot if it is already imported, otherwise
it is safe to just set the rcParams and not go through the full
plt.switch_backend path.

closes#17763

This seems difficult to test given that it is dependent on import order.

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant

@tacaswelltacaswell added this to thev3.3.0 milestoneJun 26, 2020
@tacaswell
Copy link
MemberAuthor

Both fair points.

In matplotlib.use we import pyplot to use `switch_backend`, howeverif the user calls  `mpl.use(...)` before importing pyplot thenduring the initial import of pyplot, before we set the selectedbackend we try to set the backend set via rcParams.This change only imports pyplot if it is already imported, otherwiseit is safe to just set the rcParams and not go through the full`plt.switch_backend` path.closesmatplotlib#17763
@tacaswell
Copy link
MemberAuthor

The test failure was real, it turns out we were relying on the implicit inuse to explode when the user asked for an unusable backend. I solved this by a) changing thebackend_fallback rcparam inuse (which I think we talked about before, but at least I was not sure about. Coming back to this again with a bit of time it seems clear that this is the correct behavior) b) add a pyplot import in the test to get the exception.

Hopefully the comments are clear?

Copy link
Contributor

@anntzeranntzer left a comment

Choose a reason for hiding this comment

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

looks reasonable.

@anntzeranntzer merged commitd2f25c9 intomatplotlib:masterJun 29, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestJun 29, 2020
timhoffm added a commit that referenced this pull requestJun 29, 2020
…764-on-v3.3.xBackport PR#17764 on branch v3.3.x (FIX: be more careful about not importing pyplot early)
@tacaswelltacaswell deleted the fix_early_use_call branchJuly 3, 2020 22:07
@tacaswelltacaswell mentioned this pull requestJul 3, 2020
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@anntzeranntzeranntzer approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.3.0
Development

Successfully merging this pull request may close these issues.

matplotlib.use('agg', force=True) does not ignore unavailable configured backend
3 participants
@tacaswell@anntzer@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp