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

Skip to content

Commit c941994

Browse files
dopplershiftstory645
authored andcommitted
Backport PR #15512: FIX: do not consider webagg and nbagg "interactive
1 parent e6a3d16 commit c941994

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/matplotlib/pyplot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,8 +2303,9 @@ def getname_val(identifier):
23032303
# requested, ignore rcParams['backend'] and force selection of a backend that
23042304
# is compatible with the current running interactive framework.
23052305
if (rcParams["backend_fallback"]
2306-
and dict.__getitem__(rcParams, "backend") in _interactive_bk
2307-
and _get_running_interactive_framework()):
2306+
and dict.__getitem__(rcParams, "backend") in (
2307+
set(_interactive_bk) - {'WebAgg', 'nbAgg'})
2308+
and cbook._get_running_interactive_framework()):
23082309
dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
23092310
# Set up the backend.
23102311
switch_backend(rcParams["backend"])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import subprocess
2+
import os
3+
import sys
4+
import pytest
5+
6+
7+
@pytest.mark.parametrize("backend", ["webagg", "nbagg"])
8+
def test_webagg_fallback(backend):
9+
if backend == "nbagg":
10+
pytest.importorskip("IPython")
11+
env = {}
12+
if os.name == "nt":
13+
env = dict(os.environ)
14+
else:
15+
env = {"DISPLAY": ""}
16+
17+
env["MPLBACKEND"] = backend
18+
19+
test_code = (
20+
"import os;"
21+
+ f"assert os.environ['MPLBACKEND'] == '{backend}';"
22+
+ "import matplotlib.pyplot as plt; "
23+
+ "print(plt.get_backend());"
24+
f"assert '{backend}' == plt.get_backend().lower();"
25+
)
26+
ret = subprocess.call([sys.executable, "-c", test_code], env=env)
27+
28+
assert ret == 0

0 commit comments

Comments
 (0)