FIX: be more careful about not importing pyplot early#17764
Merged
Conversation
timhoffm
reviewed
Jun 26, 2020
anntzer
reviewed
Jun 26, 2020
Member
Author
|
Both fair points. |
a5a1311 to
c9464aa
Compare
In matplotlib.use we import pyplot to use `switch_backend`, however if the user calls `mpl.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 matplotlib#17763
c9464aa to
b94f5c0
Compare
Member
Author
|
The test failure was real, it turns out we were relying on the implicit in Hopefully the comments are clear? |
timhoffm
approved these changes
Jun 28, 2020
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Jun 29, 2020
timhoffm
added a commit
that referenced
this pull request
Jun 29, 2020
…764-on-v3.3.x Backport PR #17764 on branch v3.3.x (FIX: be more careful about not importing pyplot early)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
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 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_backendpath.closes #17763
This seems difficult to test given that it is dependent on import order.
PR Checklist