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

Skip to content

Commit 30d764b

Browse files
committed
Don't update style-blacklisted rcparams in rc_* functions.
This avoids incorrectly updating e.g. the ``backend`` or ``interactive`` rcParams.
1 parent f4b5618 commit 30d764b

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Blacklisted rcparams no longer updated by `rcdefaults`, `rc_file_defaults`, `rc_file`
2+
-------------------------------------------------------------------------------------
3+
4+
The rc modifier functions `rcdefaults`, `rc_file_defaults` and `rc_file`
5+
now ignore rcParams in the `matplotlib.style.core.STYLE_BLACKLIST` set. In
6+
particular, this prevents the ``backend`` and ``interactive`` rcParams from
7+
being incorrectly modified by these functions.

lib/matplotlib/__init__.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,11 @@ def rc(group, **kwargs):
12051205

12061206

12071207
def rcdefaults():
1208-
"""Restore the rc params from Matplotlib's internal defaults.
1208+
"""
1209+
Restore the rc params from Matplotlib's internal default style.
1210+
1211+
Style-blacklisted rc params (defined in
1212+
`matplotlib.style.core.STYLE_BLACKLIST`) are not updated.
12091213
12101214
See Also
12111215
--------
@@ -1219,29 +1223,42 @@ def rcdefaults():
12191223
# no need to reemit them here.
12201224
with warnings.catch_warnings():
12211225
warnings.simplefilter("ignore", mplDeprecation)
1226+
from .style.core import STYLE_BLACKLIST
12221227
rcParams.clear()
1223-
rcParams.update(rcParamsDefault)
1228+
rcParams.update({k: v for k, v in rcParamsDefault.items()
1229+
if k not in STYLE_BLACKLIST})
12241230

12251231

12261232
def rc_file_defaults():
1227-
"""Restore the rc params from the original rc file loaded by Matplotlib.
1233+
"""
1234+
Restore the rc params from the original rc file loaded by Matplotlib.
1235+
1236+
Style-blacklisted rc params (defined in
1237+
`matplotlib.style.core.STYLE_BLACKLIST`) are not updated.
12281238
"""
12291239
# Deprecation warnings were already handled when creating rcParamsOrig, no
12301240
# need to reemit them here.
12311241
with warnings.catch_warnings():
12321242
warnings.simplefilter("ignore", mplDeprecation)
1233-
rcParams.update(rcParamsOrig)
1243+
from .style.core import STYLE_BLACKLIST
1244+
rcParams.update({k: v for k, v in rcParamsOrig.items()
1245+
if k not in STYLE_BLACKLIST})
12341246

12351247

12361248
def rc_file(fname):
12371249
"""
12381250
Update rc params from file.
1251+
1252+
Style-blacklisted rc params (defined in
1253+
`matplotlib.style.core.STYLE_BLACKLIST`) are not updated.
12391254
"""
12401255
# Deprecation warnings were already handled in rc_params_from_file, no need
12411256
# to reemit them here.
12421257
with warnings.catch_warnings():
12431258
warnings.simplefilter("ignore", mplDeprecation)
1244-
rcParams.update(rc_params_from_file(fname))
1259+
from .style.core import STYLE_BLACKLIST
1260+
rcParams.update({k: v for k, v in rc_params_from_file(fname).items()
1261+
if k not in STYLE_BLACKLIST})
12451262

12461263

12471264
class rc_context:

0 commit comments

Comments
 (0)