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

Skip to content

Commit c6e0660

Browse files
committed
Cleanup matplotlib.use
1 parent 0c35833 commit c6e0660

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

lib/matplotlib/__init__.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,15 +1297,15 @@ def __exit__(self, exc_type, exc_value, exc_tb):
12971297
self.__fallback()
12981298

12991299

1300-
def use(arg, warn=False, force=True):
1300+
def use(backend, warn=False, force=True):
13011301
"""
1302-
Set the matplotlib backend to one of the known backends.
1302+
Select the matplotlib backend for rendering.
13031303
13041304
Parameters
13051305
----------
1306-
arg : str
1307-
The backend to switch to. This can either be one of the
1308-
'standard' backend names:
1306+
backend : str
1307+
The backend to switch to. This can either be one of the standard
1308+
backend names:
13091309
13101310
- interactive backends:
13111311
GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
@@ -1319,37 +1319,34 @@ def use(arg, warn=False, force=True):
13191319
13201320
Note: Standard backend names are case-insensitive here.
13211321
1322-
warn : bool, optional
1323-
If True, warn if this is called after pyplot has been imported
1324-
and a backend is set up.
1322+
warn : bool, optional, default: False
1323+
If True and not *force*, warn that the call will have no effect if
1324+
this is called after pyplot has been imported and a backend is set up.
13251325
1326-
defaults to False.
1327-
1328-
force : bool, optional
1326+
force : bool, optional, default: True
13291327
If True, attempt to switch the backend. An ImportError is raised if
13301328
an interactive backend is selected, but another interactive
1331-
backend has already started. This defaults to True.
1329+
backend has already started.
13321330
13331331
See Also
13341332
--------
13351333
:ref:`backends`
13361334
matplotlib.get_backend
13371335
"""
1338-
name = validate_backend(arg)
1336+
name = validate_backend(backend)
13391337

1340-
# if setting back to the same thing, do nothing
1341-
if (dict.__getitem__(rcParams, 'backend') == name):
1338+
if dict.__getitem__(rcParams, 'backend') == name:
1339+
# Nothing to do if the requested backend is already set
13421340
pass
1343-
1344-
# Check if we have already imported pyplot and triggered
1345-
# backend selection, do a bit more work
13461341
elif 'matplotlib.pyplot' in sys.modules:
1347-
# If we are here then the requested is different than the current.
1342+
# pyplot has already been imported (which triggered backend selection)
1343+
# and the requested backend is different from the current one.
1344+
13481345
# If we are going to force the switch, never warn, else, if warn
13491346
# is True, then direct users to `plt.switch_backend`
13501347
if (not force) and warn:
13511348
cbook._warn_external(
1352-
("matplotlib.pyplot as already been imported, "
1349+
("matplotlib.pyplot has already been imported, "
13531350
"this call will have no effect."))
13541351

13551352
# if we are going to force switching the backend, pull in
@@ -1358,11 +1355,11 @@ def use(arg, warn=False, force=True):
13581355
if force:
13591356
from matplotlib.pyplot import switch_backend
13601357
switch_backend(name)
1361-
# Finally if pyplot is not imported update both rcParams and
1362-
# rcDefaults so restoring the defaults later with rcdefaults
1363-
# won't change the backend. This is a bit of overkill as 'backend'
1364-
# is already in style.core.STYLE_BLACKLIST, but better to be safe.
13651358
else:
1359+
# Finally if pyplot is not imported update both rcParams and
1360+
# rcDefaults so restoring the defaults later with rcdefaults
1361+
# won't change the backend. This is a bit of overkill as 'backend'
1362+
# is already in style.core.STYLE_BLACKLIST, but better to be safe.
13661363
rcParams['backend'] = rcParamsDefault['backend'] = name
13671364

13681365

0 commit comments

Comments
 (0)