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

Skip to content

Commit 11a4071

Browse files
authored
Merge pull request #23299 from tacaswell/enh/excludelist-on_rc_context
FIX/API: do not reset backend key in rc_context
2 parents b02334b + 4d6bab4 commit 11a4071

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mpl.rc_context no longer resets the value of ``'backend'``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
`matplotlib.rc_context` incorrectly reset the value of :rc:`backend` if backend
5+
resolution was triggered in the context. This affected only the value. The actual backend
6+
was not changed. Now, `matplotlib.rc_context` does not reset :rc:`backend` anymore.

lib/matplotlib/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ def rc_context(rc=None, fname=None):
10591059
"""
10601060
Return a context manager for temporarily changing rcParams.
10611061
1062+
The :rc:`backend` will not be reset by the context manager.
1063+
10621064
Parameters
10631065
----------
10641066
rc : dict
@@ -1087,7 +1089,8 @@ def rc_context(rc=None, fname=None):
10871089
plt.plot(x, y) # uses 'print.rc'
10881090
10891091
"""
1090-
orig = rcParams.copy()
1092+
orig = dict(rcParams.copy())
1093+
del orig['backend']
10911094
try:
10921095
if fname:
10931096
rc_file(fname)

lib/matplotlib/tests/test_rcparams.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ def test_keymaps():
496496
assert isinstance(mpl.rcParams[k], list)
497497

498498

499+
def test_no_backend_reset_rccontext():
500+
assert mpl.rcParams['backend'] != 'module://aardvark'
501+
with mpl.rc_context():
502+
mpl.rcParams['backend'] = 'module://aardvark'
503+
assert mpl.rcParams['backend'] == 'module://aardvark'
504+
505+
499506
def test_rcparams_reset_after_fail():
500507
# There was previously a bug that meant that if rc_context failed and
501508
# raised an exception due to issues in the supplied rc parameters, the

0 commit comments

Comments
 (0)