-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: allow matplotlib.use after getbackend #12608
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
Conversation
lib/matplotlib/__init__.py
Outdated
|
||
force : bool, optional | ||
If True, attempt to switch the backend. This defaults to | ||
False. | ||
True. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention that this will raise ImportError on failure, which occurs if an incompatible event loop has already started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except for minor doc improvement
@@ -1292,7 +1292,7 @@ def __exit__(self, exc_type, exc_value, exc_tb): | |||
self.__fallback() | |||
|
|||
|
|||
def use(arg, warn=True, force=False): | |||
def use(arg, warn=False, force=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's very remotely an API break in the sense that some previously invalid calls to use() would raise a warning and do nothing whereas they will now throw an exception, but I'm not sure if it's worth an API note :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API note added. As per below I wonder if we really want to stick closer to the original behaviour and trap the Error, warn, and not switch the backend.
This is the API change we decided not to make for 3.0. I am still skeptical, but slowing coming around to this being the right path. |
I thought the API discussion was about the role of rcParams in all this. But since that’s what we do now, changing that can wait. Of course the way things are before this PR we could have been telling people to use Force=True |
BTW, I'd also be fine w/ import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('Qt5Agg')
plt.plot(range(10)); plt.show()
matplotlib.use('MacOSX') warning and doing nothing, rather than throwing an ImportError. It'd be easy to trap the ImportError. |
It's not as if it was particularly hard for the end user to catch the import error, and not everyone reads warnings (in the long term I'd like to get rid of force and warn, which are kind of silly now that backend switching works, but that's for another day...). |
@anntzer, I agree, but that behaviour is not as key to me as the ability for |
re-milestoned out of 3.0.1 as I want to think about this a bit more not under the pressure of "we need to get out a bug-fix-release that works on py3.7.1" |
Just to get folks thinking about this, what are the cons of this change? |
…608-on-v3.0.x Backport PR #12608 on branch v3.0.x (ENH: allow matplotlib.use after getbackend)
On a bit more consideration, I suspect we are going to get a wave of "why are my figures not interactive?" bug reports that trace back to the GUI wrappers installing conflicting input hooks. |
but we will deal with that when it happens. |
Again, hopefully input hooks are only installed when the event loop is started, not when the package is imported. |
PR Summary
Closes the long-desired ability to just call
matplotlib.use
so long as another GUI backend hasn't been started:Closes #12362 (for example)
With this PR:
Before:
PR Checklist