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

Skip to content

Commit fccf3d9

Browse files
authored
Merge pull request #15582 from story645/auto-backport-of-pr-15512-on-v3.1.x
Backport PR #15512 on branch v3.1.x
2 parents 83f686c + eb5a3d7 commit fccf3d9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,8 @@ def getname_val(identifier):
23412341
# requested, ignore rcParams['backend'] and force selection of a backend that
23422342
# is compatible with the current running interactive framework.
23432343
if (rcParams["backend_fallback"]
2344-
and dict.__getitem__(rcParams, "backend") in _interactive_bk
2344+
and dict.__getitem__(rcParams, "backend") in (
2345+
set(_interactive_bk) - {'WebAgg', 'nbAgg'})
23452346
and _get_running_interactive_framework()):
23462347
dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
23472348
# Set up the 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)