@@ -1262,7 +1262,6 @@ def use(backend, warn=False, force=True):
1262
1262
If True and not *force*, warn that the call will have no effect if
1263
1263
this is called after pyplot has been imported and a backend is set up.
1264
1264
1265
-
1266
1265
force : bool, optional, default: True
1267
1266
If True, attempt to switch the backend. An ImportError is raised if
1268
1267
an interactive backend is selected, but another interactive
@@ -1281,20 +1280,17 @@ def use(backend, warn=False, force=True):
1281
1280
elif 'matplotlib.pyplot' in sys .modules :
1282
1281
# pyplot has already been imported (which triggered backend selection)
1283
1282
# and the requested backend is different from the current one.
1284
-
1285
- # If we are going to force the switch, never warn, else, if warn
1286
- # is True, then direct users to `plt.switch_backend`
1287
- if (not force ) and warn :
1288
- cbook ._warn_external (
1289
- "matplotlib.pyplot has already been imported, "
1290
- "this call will have no effect." )
1291
-
1292
- # if we are going to force switching the backend, pull in
1293
- # `switch_backend` from pyplot. This will only happen if
1294
- # pyplot is already imported.
1295
1283
if force :
1284
+ # if we are going to force switching the backend, pull in
1285
+ # `switch_backend` from pyplot (which is already imported).
1296
1286
from matplotlib .pyplot import switch_backend
1297
1287
switch_backend (name )
1288
+ elif warn :
1289
+ # Only if we are not going to force the switch *and* warn is True,
1290
+ # then direct users to `plt.switch_backend`.
1291
+ cbook ._warn_external (
1292
+ "matplotlib.pyplot has already been imported, "
1293
+ "this call will have no effect." )
1298
1294
else :
1299
1295
# Finally if pyplot is not imported update both rcParams and
1300
1296
# rcDefaults so restoring the defaults later with rcdefaults
@@ -1385,6 +1381,7 @@ def _init_tests():
1385
1381
raise
1386
1382
1387
1383
1384
+ @cbook ._delete_parameter ("3.2" , "switch_backend_warn" )
1388
1385
def test (verbosity = None , coverage = False , switch_backend_warn = True ,
1389
1386
recursionlimit = 0 , ** kwargs ):
1390
1387
"""Run the matplotlib test suite."""
@@ -1426,7 +1423,7 @@ def test(verbosity=None, coverage=False, switch_backend_warn=True,
1426
1423
retcode = pytest .main (args , ** kwargs )
1427
1424
finally :
1428
1425
if old_backend .lower () != 'agg' :
1429
- use (old_backend , warn = switch_backend_warn )
1426
+ use (old_backend )
1430
1427
if recursionlimit :
1431
1428
sys .setrecursionlimit (old_recursionlimit )
1432
1429
0 commit comments