Skip to content

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

Merged
merged 3 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/2018-10-24-JMK.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Matplotlib.use now has an ImportError for interactive backend
-------------------------------------------------------------

Switching backends via `matplotlib.use` is now allowed by default,
regardless of whether `matplotlib.pyplot` has been imported. If the user
tries to switch from an already-started interactive backend to a different
interactive backend, an ImportError will be raised.
9 changes: 5 additions & 4 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Contributor

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 :)

Copy link
Member Author

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.

"""
Set the matplotlib backend to one of the known backends.

Expand All @@ -1318,11 +1318,12 @@ def use(arg, warn=True, force=False):
If True, warn if this is called after pyplot has been imported
and a backend is set up.

defaults to True
defaults to False.

force : bool, optional
If True, attempt to switch the backend. This defaults to
False.
If True, attempt to switch the backend. An ImportError is raised if
an interactive backend is selected, but another interactive
backend has already started. This defaults to True.

See Also
--------
Expand Down