Skip to content

Commit 15e8d38

Browse files
authored
Merge pull request #16262 from anntzer/rcbackend
MNT: Dedupe update of rcParams["backend"] in use() and in switch_backend()
2 parents 9005a13 + 016c694 commit 15e8d38

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ def rcdefaults():
971971
--------
972972
rc_file_defaults
973973
Restore the rc params from the rc file originally loaded by Matplotlib.
974-
matplotlib.style.use :
974+
matplotlib.style.use
975975
Use a specific style file. Call ``style.use('default')`` to restore
976976
the default style.
977977
"""
@@ -1124,11 +1124,6 @@ def use(backend, *, force=True):
11241124
# Nothing to do if the requested backend is already set
11251125
pass
11261126
else:
1127-
# Update both rcParams and rcDefaults so restoring the defaults later
1128-
# with rcdefaults won't change the backend. This is a bit of overkill
1129-
# as 'backend' is already in style.core.STYLE_BLACKLIST, but better to
1130-
# be safe.
1131-
rcParams['backend'] = rcParamsDefault['backend'] = name
11321127
try:
11331128
from matplotlib import pyplot as plt
11341129
plt.switch_backend(name)

lib/matplotlib/pyplot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def switch_backend(newbackend):
229229
"framework, as {!r} is currently running".format(
230230
newbackend, required_framework, current_framework))
231231

232+
# Update both rcParams and rcDefaults so restoring the defaults later with
233+
# rcdefaults won't change the backend. A bit of overkill as 'backend' is
234+
# already in style.core.STYLE_BLACKLIST, but better to be safe.
232235
rcParams['backend'] = rcParamsDefault['backend'] = newbackend
233236

234237
global _backend_mod, new_figure_manager, draw_if_interactive, _show

0 commit comments

Comments
 (0)