Skip to content

Commit 54b6964

Browse files
committed
Update rcdefaults to use style.core.use()
1 parent 57d742c commit 54b6964

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

lib/matplotlib/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,13 +1249,10 @@ def rcdefaults():
12491249
Use a specific style file. Call ``style.use('default')`` to restore
12501250
the default style.
12511251
"""
1252-
# Deprecation warnings were already handled when creating rcParamsDefault,
1253-
# no need to reemit them here.
1254-
with _api.suppress_matplotlib_deprecation_warning():
1255-
from .style.core import STYLE_BLACKLIST
1256-
rcParams.clear()
1257-
# rcParams.update({k: v for k, v in rcParams.items()
1258-
# if k not in STYLE_BLACKLIST})
1252+
# # Deprecation warnings were already handled when creating rcParamsDefault,
1253+
# # no need to reemit them here.
1254+
from .style import core
1255+
core.use('default')
12591256

12601257

12611258
def rc_file_defaults():

lib/matplotlib/style/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def use(style):
149149
else:
150150
filtered[k] = style[k]
151151
mpl.rcParams.update(filtered)
152+
mpl.rcParams._new_child()
152153

153154

154155
@contextlib.contextmanager

lib/matplotlib/tests/test_rcparams.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,17 @@ def test_rcparams_getdefaults():
609609
defaults = mpl.rcParams.getdefaults()
610610
mpl.rcParams.clear()
611611
assert defaults == mpl.rcParams
612+
613+
614+
def test_rcdefaults():
615+
# webagg.port is a style blacklisted key that shouldn't be
616+
# updated when resetting rcParams to default values.
617+
mpl.rcParams["webagg.port"] = 9000
618+
# lines.linewidth is not a style blacklisted key and should be
619+
# reset to the default value.
620+
# breakpoint()
621+
lw = mpl.rcParams.getdefault("lines.linewidth")
622+
mpl.rcParams["lines.linewidth"] = lw + 1
623+
mpl.rcdefaults()
624+
assert mpl.rcParams["webagg.port"] == 9000
625+
assert mpl.rcParams["lines.linewidth"] == lw

0 commit comments

Comments
 (0)