Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c689eac

Browse filesBrowse files
committed
Also update the backend when doing rcParams["backend"] = "foo".
1 parent 33aa68c commit c689eac
Copy full SHA for c689eac

File tree

Expand file treeCollapse file tree

3 files changed

+24
-10
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-10
lines changed

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,28 @@ def validate_backend(s):
262262
lambda s:
263263
s if s.startswith("module://")
264264
else ValidateInStrings('backend', all_backends, ignorecase=True)(s))(s)
265+
pyplot = sys.modules.get("matplotlib.pyplot")
265266
if len(candidates) == 1:
266-
return candidates[0]
267+
backend, = candidates
268+
if pyplot:
269+
# This import needs to be delayed (below too) because it is not
270+
# available at first import.
271+
from matplotlib import rcParams
272+
# Don't recurse.
273+
old_backend = rcParams["backend"]
274+
if old_backend == backend:
275+
return backend
276+
dict.__setitem__(rcParams, "backend", backend)
277+
try:
278+
pyplot.switch_backend(backend)
279+
except Exception:
280+
dict.__setitem__(rcParams, "backend", old_backend)
281+
raise
282+
return backend
267283
else:
268-
pyplot = sys.modules.get("matplotlib.pyplot")
269284
if pyplot:
270-
pyplot.switch_backend(candidates) # Actually resolves the backend.
271285
from matplotlib import rcParams
286+
pyplot.switch_backend(candidates) # Actually resolves the backend.
272287
return rcParams["backend"]
273288
else:
274289
return candidates

‎lib/matplotlib/tests/test_backend_qt4.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt4.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
except ImportError:
1414
import mock
1515

16-
with matplotlib.rc_context(rc={'backend': 'Qt4Agg'}):
17-
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat')
18-
from matplotlib.backends.backend_qt4 import (
19-
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa
16+
pytest.importorskip('PyQt4')
17+
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat')
2018

2119
QtCore = qt_compat.QtCore
2220
_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]

‎lib/matplotlib/tests/test_backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt5.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
except ImportError:
1717
import mock
1818

19-
with matplotlib.rc_context(rc={'backend': 'Qt5Agg'}):
20-
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat',
21-
minversion='5')
19+
pytest.importorskip('PyQt5')
20+
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat',
21+
minversion='5')
22+
2223
from matplotlib.backends.backend_qt5 import (
2324
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa
2425

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.