@@ -1297,15 +1297,15 @@ def __exit__(self, exc_type, exc_value, exc_tb):
1297
1297
self .__fallback ()
1298
1298
1299
1299
1300
- def use (arg , warn = False , force = True ):
1300
+ def use (backend , warn = False , force = True ):
1301
1301
"""
1302
- Set the matplotlib backend to one of the known backends .
1302
+ Select the matplotlib backend for rendering .
1303
1303
1304
1304
Parameters
1305
1305
----------
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:
1309
1309
1310
1310
- interactive backends:
1311
1311
GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
@@ -1319,37 +1319,34 @@ def use(arg, warn=False, force=True):
1319
1319
1320
1320
Note: Standard backend names are case-insensitive here.
1321
1321
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.
1325
1325
1326
- defaults to False.
1327
-
1328
- force : bool, optional
1326
+ force : bool, optional, default: True
1329
1327
If True, attempt to switch the backend. An ImportError is raised if
1330
1328
an interactive backend is selected, but another interactive
1331
- backend has already started. This defaults to True.
1329
+ backend has already started.
1332
1330
1333
1331
See Also
1334
1332
--------
1335
1333
:ref:`backends`
1336
1334
matplotlib.get_backend
1337
1335
"""
1338
- name = validate_backend (arg )
1336
+ name = validate_backend (backend )
1339
1337
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
1342
1340
pass
1343
-
1344
- # Check if we have already imported pyplot and triggered
1345
- # backend selection, do a bit more work
1346
1341
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
+
1348
1345
# If we are going to force the switch, never warn, else, if warn
1349
1346
# is True, then direct users to `plt.switch_backend`
1350
1347
if (not force ) and warn :
1351
1348
cbook ._warn_external (
1352
- ("matplotlib.pyplot as already been imported, "
1349
+ ("matplotlib.pyplot has already been imported, "
1353
1350
"this call will have no effect." ))
1354
1351
1355
1352
# if we are going to force switching the backend, pull in
@@ -1358,11 +1355,11 @@ def use(arg, warn=False, force=True):
1358
1355
if force :
1359
1356
from matplotlib .pyplot import switch_backend
1360
1357
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.
1365
1358
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.
1366
1363
rcParams ['backend' ] = rcParamsDefault ['backend' ] = name
1367
1364
1368
1365
0 commit comments