Skip to content

Commit 126de7f

Browse files
authored
Merge pull request #15512 from tacaswell/fix_webagg_fallback
FIX: do not consider webagg and nbagg "interactive" for fallback
2 parents 3a811a2 + 557e56f commit 126de7f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/matplotlib/pyplot.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,8 @@ def getname_val(identifier):
22442244
# requested, ignore rcParams['backend'] and force selection of a backend that
22452245
# is compatible with the current running interactive framework.
22462246
if (rcParams["backend_fallback"]
2247-
and dict.__getitem__(rcParams, "backend") in _interactive_bk
2247+
and dict.__getitem__(rcParams, "backend") in (
2248+
set(_interactive_bk) - {'WebAgg', 'nbAgg'})
22482249
and cbook._get_running_interactive_framework()):
22492250
dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
22502251
# Set up the backend.
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)