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

Safely import pyplot if a GUI framework is already running.#18316

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
QuLogic merged 1 commit intomatplotlib:masterfromanntzer:safe_pyplot_import
Aug 22, 2020

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedAug 21, 2020
edited
Loading

configure_subplots now needs to importpyplot (because that's
how we can spin up a new figure as needed), but when relying on
embedding we could well reach that point with an already running
interactive framework, pyplot never imported, and an incompatible
rcParams["backend"] (which had not been read yet). For example, run
examples/user_interfaces/embedding_in_tk_sgskip.py with a non-tk
backend set in your matplotlibrc: clicking on the the configure_subplots
button triggers a "cannot load backend 'foo' which requires the 'foo'
interactive framework, as 'bar' is currently running".

Instead, use a helper to safely import pyplot when another interactive
framework may already be running. The list of frameworks that
_get_running_interactive_framework returns is fixed, so we can just
hardcode the mapping. (We are going to ignore the user-set
rcParams["backend"] anyways.)

followup to#16818, especially#16818 (review) (which this does not fix, it's just the easy first step).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 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/next_api_changes/* if API changed in a backward-incompatible way

`configure_subplots` now needs to import `pyplot` (because that'show we can spin up a new figure as needed), but when relying onembedding we could well reach that point with an already runninginteractive framework, pyplot never imported, and an incompatiblercParams["backend"] (which had not been read yet).  For example, run`examples/user_interfaces/embedding_in_tk_sgskip.py` with a non-tkbackend set in your matplotlibrc: clicking on the the configure_subplotsbutton triggers a "cannot load backend 'foo' which requires the 'foo'interactive framework, as 'bar' is currently running".Instead, use a helper to safely import pyplot when another interactiveframework may already be running.  The list of frameworks that`_get_running_interactive_framework` returns is fixed, so we can justhardcode the mapping.  (We are going to ignore the user-set`rcParams["backend"]` anyways.)
@anntzeranntzer added this to thev3.4.0 milestoneAug 21, 2020
@tacaswell
Copy link
Member

Does this catch a case not covered by#18245 ?

@anntzer
Copy link
ContributorAuthor

This is independent of#18245: herercParams["backend"] != auto_backend_sentinel, but we still want to fallback because we're forced anyways.

@tacaswell
Copy link
Member

feels a bit like epicycles, but still suspect that this is moving us in the direction of a simplification.

@QuLogicQuLogic merged commit3d725f6 intomatplotlib:masterAug 22, 2020
@anntzeranntzer deleted the safe_pyplot_import branchNovember 16, 2021 14:52
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@QuLogicQuLogicQuLogic approved these changes

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

Successfully merging this pull request may close these issues.

3 participants
@anntzer@tacaswell@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp