@@ -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, which are case-insensitive :
1309
1309
1310
1310
- interactive backends:
1311
1311
GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
@@ -1317,52 +1317,47 @@ def use(arg, warn=False, force=True):
1317
1317
1318
1318
or a string of the form: ``module://my.module.name``.
1319
1319
1320
- Note: Standard backend names are case-insensitive here.
1320
+ warn : bool, optional, default: False
1321
+ If True and not *force*, warn that the call will have no effect if
1322
+ this is called after pyplot has been imported and a backend is set up.
1321
1323
1322
- warn : bool, optional
1323
- If True, warn if this is called after pyplot has been imported
1324
- and a backend is set up.
1325
-
1326
- defaults to False.
1327
-
1328
- force : bool, optional
1324
+ force : bool, optional, default: True
1329
1325
If True, attempt to switch the backend. An ImportError is raised if
1330
1326
an interactive backend is selected, but another interactive
1331
- backend has already started. This defaults to True.
1327
+ backend has already started.
1332
1328
1333
1329
See Also
1334
1330
--------
1335
1331
:ref:`backends`
1336
1332
matplotlib.get_backend
1337
1333
"""
1338
- name = validate_backend (arg )
1334
+ name = validate_backend (backend )
1339
1335
1340
- # if setting back to the same thing, do nothing
1341
- if ( dict . __getitem__ ( rcParams , ' backend' ) == name ):
1336
+ if dict . __getitem__ ( rcParams , 'backend' ) == name :
1337
+ # Nothing to do if the requested backend is already set
1342
1338
pass
1343
-
1344
- # Check if we have already imported pyplot and triggered
1345
- # backend selection, do a bit more work
1346
1339
elif 'matplotlib.pyplot' in sys .modules :
1347
- # If we are here then the requested is different than the current.
1340
+ # pyplot has already been imported (which triggered backend selection)
1341
+ # and the requested backend is different from the current one.
1342
+
1348
1343
# If we are going to force the switch, never warn, else, if warn
1349
1344
# is True, then direct users to `plt.switch_backend`
1350
1345
if (not force ) and warn :
1351
1346
cbook ._warn_external (
1352
- ( "matplotlib.pyplot as already been imported, "
1353
- "this call will have no effect." ) )
1347
+ "matplotlib.pyplot has already been imported, "
1348
+ "this call will have no effect." )
1354
1349
1355
1350
# if we are going to force switching the backend, pull in
1356
1351
# `switch_backend` from pyplot. This will only happen if
1357
1352
# pyplot is already imported.
1358
1353
if force :
1359
1354
from matplotlib .pyplot import switch_backend
1360
1355
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
1356
else :
1357
+ # Finally if pyplot is not imported update both rcParams and
1358
+ # rcDefaults so restoring the defaults later with rcdefaults
1359
+ # won't change the backend. This is a bit of overkill as 'backend'
1360
+ # is already in style.core.STYLE_BLACKLIST, but better to be safe.
1366
1361
rcParams ['backend' ] = rcParamsDefault ['backend' ] = name
1367
1362
1368
1363
0 commit comments