Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f76bf2

Browse files
committed
Cleanup matplotlib.use
1 parent d7c6c5b commit 5f76bf2

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
API Changes
2+
```````````
3+
4+
The first parameter of `matplotlib.use` has been renamed from *arg* to
5+
*backend*. This will only affect cases where that parameter has been set
6+
as a keyword argument. The common usage pattern as a positional argument
7+
``matplotlib.use('Qt5Agg')`` is not affected.

lib/matplotlib/__init__.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,13 +1184,13 @@ def __exit__(self, exc_type, exc_value, exc_tb):
11841184
@cbook._rename_parameter("3.1", "arg", "backend")
11851185
def use(backend, warn=False, force=True):
11861186
"""
1187-
Set the matplotlib backend to one of the known backends.
1187+
Select the backend used for rendering and GUI integration.
11881188
11891189
Parameters
11901190
----------
11911191
backend : str
1192-
The backend to switch to. This can either be one of the
1193-
'standard' backend names:
1192+
The backend to switch to. This can either be one of the standard
1193+
backend names, which are case-insensitive:
11941194
11951195
- interactive backends:
11961196
GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
@@ -1202,20 +1202,15 @@ def use(backend, warn=False, force=True):
12021202
12031203
or a string of the form: ``module://my.module.name``.
12041204
1205-
Note: Standard backend names are case-insensitive here.
1205+
warn : bool, optional, default: False
1206+
If True and not *force*, warn that the call will have no effect if
1207+
this is called after pyplot has been imported and a backend is set up.
12061208
1207-
*arg* is a deprecated synonym for this parameter.
12081209
1209-
warn : bool, optional
1210-
If True, warn if this is called after pyplot has been imported
1211-
and a backend is set up.
1212-
1213-
defaults to False.
1214-
1215-
force : bool, optional
1210+
force : bool, optional, default: True
12161211
If True, attempt to switch the backend. An ImportError is raised if
12171212
an interactive backend is selected, but another interactive
1218-
backend has already started. This defaults to True.
1213+
backend has already started.
12191214
12201215
See Also
12211216
--------
@@ -1224,32 +1219,31 @@ def use(backend, warn=False, force=True):
12241219
"""
12251220
name = validate_backend(backend)
12261221

1227-
# if setting back to the same thing, do nothing
1228-
if (dict.__getitem__(rcParams, 'backend') == name):
1222+
if dict.__getitem__(rcParams, 'backend') == name:
1223+
# Nothing to do if the requested backend is already set
12291224
pass
1230-
1231-
# Check if we have already imported pyplot and triggered
1232-
# backend selection, do a bit more work
12331225
elif 'matplotlib.pyplot' in sys.modules:
1234-
# If we are here then the requested is different than the current.
1226+
# pyplot has already been imported (which triggered backend selection)
1227+
# and the requested backend is different from the current one.
1228+
12351229
# If we are going to force the switch, never warn, else, if warn
12361230
# is True, then direct users to `plt.switch_backend`
12371231
if (not force) and warn:
12381232
cbook._warn_external(
1239-
("matplotlib.pyplot as already been imported, "
1240-
"this call will have no effect."))
1233+
"matplotlib.pyplot has already been imported, "
1234+
"this call will have no effect.")
12411235

12421236
# if we are going to force switching the backend, pull in
12431237
# `switch_backend` from pyplot. This will only happen if
12441238
# pyplot is already imported.
12451239
if force:
12461240
from matplotlib.pyplot import switch_backend
12471241
switch_backend(name)
1248-
# Finally if pyplot is not imported update both rcParams and
1249-
# rcDefaults so restoring the defaults later with rcdefaults
1250-
# won't change the backend. This is a bit of overkill as 'backend'
1251-
# is already in style.core.STYLE_BLACKLIST, but better to be safe.
12521242
else:
1243+
# Finally if pyplot is not imported update both rcParams and
1244+
# rcDefaults so restoring the defaults later with rcdefaults
1245+
# won't change the backend. This is a bit of overkill as 'backend'
1246+
# is already in style.core.STYLE_BLACKLIST, but better to be safe.
12531247
rcParams['backend'] = rcParamsDefault['backend'] = name
12541248

12551249

0 commit comments

Comments
 (0)