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 fe82135

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

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
@@ -261,13 +261,28 @@ def validate_backend(s):
261261
lambda s:
262262
s if s.startswith("module://")
263263
else ValidateInStrings('backend', all_backends, ignorecase=True)(s))(s)
264+
pyplot = sys.modules.get("matplotlib.pyplot")
264265
if len(candidates) == 1:
265-
return candidates[0]
266+
backend, = candidates
267+
if pyplot:
268+
# This import needs to be delayed (below too) because it is not
269+
# available at first import.
270+
from matplotlib import rcParams
271+
# Don't recurse.
272+
old_backend = rcParams["backend"]
273+
if old_backend == backend:
274+
return backend
275+
dict.__setitem__(rcParams, "backend", backend)
276+
try:
277+
pyplot.switch_backend(backend)
278+
except Exception:
279+
dict.__setitem__(rcParams, "backend", old_backend)
280+
raise
281+
return backend
266282
else:
267-
pyplot = sys.modules.get("matplotlib.pyplot")
268283
if pyplot:
269-
pyplot.switch_backend(candidates) # Actually resolves the backend.
270284
from matplotlib import rcParams
285+
pyplot.switch_backend(candidates) # Actually resolves the backend.
271286
return rcParams["backend"]
272287
else:
273288
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
@@ -12,10 +12,8 @@
1212
except ImportError:
1313
import mock
1414

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

2018
QtCore = qt_compat.QtCore
2119
_, 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
@@ -15,9 +15,10 @@
1515
except ImportError:
1616
import mock
1717

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

0 commit comments

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