Skip to content

Commit c23cb29

Browse files
committed
Update rcdefaults to use style.core.use()
1 parent 7e4022a commit c23cb29

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
@@ -1254,13 +1254,10 @@ def rcdefaults():
12541254
Use a specific style file. Call ``style.use('default')`` to restore
12551255
the default style.
12561256
"""
1257-
# Deprecation warnings were already handled when creating rcParamsDefault,
1258-
# no need to reemit them here.
1259-
with _api.suppress_matplotlib_deprecation_warning():
1260-
from .style.core import STYLE_BLACKLIST
1261-
rcParams.clear()
1262-
# rcParams.update({k: v for k, v in rcParams.items()
1263-
# if k not in STYLE_BLACKLIST})
1257+
# # Deprecation warnings were already handled when creating rcParamsDefault,
1258+
# # no need to reemit them here.
1259+
from .style import core
1260+
core.use('default')
12641261

12651262

12661263
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
@@ -664,3 +664,17 @@ def test_rcparams_getdefaults():
664664
defaults = mpl.rcParams.getdefaults()
665665
mpl.rcParams.clear()
666666
assert defaults == mpl.rcParams
667+
668+
669+
def test_rcdefaults():
670+
# webagg.port is a style blacklisted key that shouldn't be
671+
# updated when resetting rcParams to default values.
672+
mpl.rcParams["webagg.port"] = 9000
673+
# lines.linewidth is not a style blacklisted key and should be
674+
# reset to the default value.
675+
# breakpoint()
676+
lw = mpl.rcParams.getdefault("lines.linewidth")
677+
mpl.rcParams["lines.linewidth"] = lw + 1
678+
mpl.rcdefaults()
679+
assert mpl.rcParams["webagg.port"] == 9000
680+
assert mpl.rcParams["lines.linewidth"] == lw

0 commit comments

Comments
 (0)