@@ -1184,13 +1184,13 @@ def __exit__(self, exc_type, exc_value, exc_tb):
1184
1184
@cbook ._rename_parameter ("3.1" , "arg" , "backend" )
1185
1185
def use (backend , warn = False , force = True ):
1186
1186
"""
1187
- Set the matplotlib backend to one of the known backends .
1187
+ Select the backend used for rendering and GUI integration .
1188
1188
1189
1189
Parameters
1190
1190
----------
1191
1191
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 :
1194
1194
1195
1195
- interactive backends:
1196
1196
GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
@@ -1202,20 +1202,15 @@ def use(backend, warn=False, force=True):
1202
1202
1203
1203
or a string of the form: ``module://my.module.name``.
1204
1204
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.
1206
1208
1207
- *arg* is a deprecated synonym for this parameter.
1208
1209
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
1216
1211
If True, attempt to switch the backend. An ImportError is raised if
1217
1212
an interactive backend is selected, but another interactive
1218
- backend has already started. This defaults to True.
1213
+ backend has already started.
1219
1214
1220
1215
See Also
1221
1216
--------
@@ -1224,32 +1219,31 @@ def use(backend, warn=False, force=True):
1224
1219
"""
1225
1220
name = validate_backend (backend )
1226
1221
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
1229
1224
pass
1230
-
1231
- # Check if we have already imported pyplot and triggered
1232
- # backend selection, do a bit more work
1233
1225
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
+
1235
1229
# If we are going to force the switch, never warn, else, if warn
1236
1230
# is True, then direct users to `plt.switch_backend`
1237
1231
if (not force ) and warn :
1238
1232
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." )
1241
1235
1242
1236
# if we are going to force switching the backend, pull in
1243
1237
# `switch_backend` from pyplot. This will only happen if
1244
1238
# pyplot is already imported.
1245
1239
if force :
1246
1240
from matplotlib .pyplot import switch_backend
1247
1241
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.
1252
1242
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.
1253
1247
rcParams ['backend' ] = rcParamsDefault ['backend' ] = name
1254
1248
1255
1249
0 commit comments