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

Skip to content

Commit 7e4022a

Browse files
committed
Remove rcParamsDefault
1 parent 67735b0 commit 7e4022a

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

lib/matplotlib/__init__.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ def getdefault(self, key):
853853

854854
return self._get_default(key)
855855

856+
def getdefaults(self):
857+
"""Return default values set during initialization."""
858+
defaults = self.copy()
859+
defaults.clear()
860+
return defaults
861+
856862
def _get_backend_or_none(self):
857863
"""Get the requested backend, if any, without triggering resolution."""
858864
backend = self._get("backend")
@@ -1110,7 +1116,7 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
11101116
return config_from_file
11111117

11121118
with _api.suppress_matplotlib_deprecation_warning():
1113-
config = RcParams({**rcParamsDefault, **config_from_file})
1119+
config = RcParams({**rcParams.getdefaults(), **config_from_file})
11141120

11151121
if "".join(config['text.latex.preamble']):
11161122
_log.info("""
@@ -1125,21 +1131,22 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
11251131
return config
11261132

11271133

1128-
rcParamsDefault = _rc_params_in_file(
1134+
rcParams = _rc_params_in_file(
11291135
cbook._get_data_path("matplotlibrc"),
11301136
# Strip leading comment.
11311137
transform=lambda line: line[1:] if line.startswith("#") else line,
11321138
fail_on_error=True)
1133-
rcParamsDefault.update(rcsetup._hardcoded_defaults)
1139+
for key in rcsetup._hardcoded_defaults:
1140+
space, subkey = key.split(".")
1141+
if not rcParams._namespace_maps[space]:
1142+
rcParams._namespace_maps[space] = ChainMap({})
1143+
rcParams.update(rcsetup._hardcoded_defaults)
11341144
# Normally, the default matplotlibrc file contains *no* entry for backend (the
11351145
# corresponding line starts with ##, not #; we fill on _auto_backend_sentinel
11361146
# in that case. However, packagers can set a different default backend
11371147
# (resulting in a normal `#backend: foo` line) in which case we should *not*
11381148
# fill in _auto_backend_sentinel.
1139-
rcParamsDefault.setdefault("backend", rcsetup._auto_backend_sentinel)
1140-
rcParams = RcParams()
1141-
rcParams._parents()
1142-
rcParams.update(rcParamsDefault.items())
1149+
rcParams.setdefault("backend", rcsetup._auto_backend_sentinel)
11431150
rcParams.update(_rc_params_in_file(matplotlib_fname()))
11441151
rcParamsOrig = rcParams.copy()
11451152
with _api.suppress_matplotlib_deprecation_warning():
@@ -1148,12 +1155,11 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
11481155
defaultParams = rcsetup.defaultParams = {
11491156
# We want to resolve deprecated rcParams, but not backend...
11501157
key: [(rcsetup._auto_backend_sentinel if key == "backend" else
1151-
rcParamsDefault[key]),
1158+
rcParams.getdefault(key)),
11521159
validator]
11531160
for key, validator in rcsetup._validators.items()}
11541161
if rcParams['axes.formatter.use_locale']:
11551162
locale.setlocale(locale.LC_ALL, '')
1156-
rcParams._new_child()
11571163

11581164

11591165
def rc(group, **kwargs):
@@ -1253,8 +1259,8 @@ def rcdefaults():
12531259
with _api.suppress_matplotlib_deprecation_warning():
12541260
from .style.core import STYLE_BLACKLIST
12551261
rcParams.clear()
1256-
rcParams.update({k: v for k, v in rcParamsDefault.items()
1257-
if k not in STYLE_BLACKLIST})
1262+
# rcParams.update({k: v for k, v in rcParams.items()
1263+
# if k not in STYLE_BLACKLIST})
12581264

12591265

12601266
def rc_file_defaults():

lib/matplotlib/pyplot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
FigureCanvasBase, FigureManagerBase, MouseButton)
6666
from matplotlib.figure import Figure, FigureBase, figaspect
6767
from matplotlib.gridspec import GridSpec, SubplotSpec
68-
from matplotlib import rcsetup, rcParamsDefault, rcParamsOrig
68+
from matplotlib import rcParams, get_backend, rcParamsOrig
69+
from matplotlib.rcsetup import interactive_bk as _interactive_bk
6970
from matplotlib.artist import Artist
7071
from matplotlib.axes import Axes, Subplot # type: ignore
7172
from matplotlib.projections import PolarAxes # type: ignore
@@ -413,7 +414,7 @@ def draw_if_interactive() -> None:
413414
_log.debug("Loaded backend %s version %s.",
414415
newbackend, backend_mod.backend_version)
415416

416-
rcParams['backend'] = rcParamsDefault['backend'] = newbackend
417+
rcParams['backend'] = newbackend
417418
_backend_mod = backend_mod
418419
for func_name in ["new_figure_manager", "draw_if_interactive", "show"]:
419420
globals()[func_name].__signature__ = inspect.signature(

lib/matplotlib/style/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import importlib_resources
2727

2828
import matplotlib as mpl
29-
from matplotlib import _api, _docstring, _rc_params_in_file, rcParamsDefault
29+
from matplotlib import _api, _docstring, _rc_params_in_file
3030

3131
_log = logging.getLogger(__name__)
3232

@@ -114,7 +114,7 @@ def use(style):
114114
# rcParamsDefault, no need to reemit them here.
115115
with _api.suppress_matplotlib_deprecation_warning():
116116
# don't trigger RcParams.__getitem__('backend')
117-
style = {k: rcParamsDefault[k] for k in rcParamsDefault
117+
style = {k: mpl.rcParams.getdefault(k) for k in mpl.rcParams
118118
if k not in STYLE_BLACKLIST}
119119
elif style in library:
120120
style = library[style]

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,14 @@ def test_anchoredtext_horizontal_alignment():
257257
ax.add_artist(text2)
258258

259259

260+
<<<<<<< HEAD
260261
@pytest.mark.parametrize("extent_kind", ["window_extent", "tightbbox"])
261262
def test_annotationbbox_extents(extent_kind):
262263
plt.rcParams.update(plt.rcParamsDefault)
264+
=======
265+
def test_annotationbbox_extents():
266+
plt.rcParams.clear()
267+
>>>>>>> 57d742c95e (Remove `rcParamsDefault`)
263268
fig, ax = plt.subplots(figsize=(4, 3), dpi=100)
264269

265270
ax.axis([0, 1, 0, 1])

lib/matplotlib/tests/test_rcparams.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,10 @@ def test_rcparams_path_sketch_from_file(tmpdir, value):
657657
def test_rcparams_getdefault():
658658
with mpl.rc_context({"image.lut": 128}):
659659
assert mpl.rcParams.getdefault("image.lut") == 256
660+
661+
662+
def test_rcparams_getdefaults():
663+
mpl.rc("image", lut=128)
664+
defaults = mpl.rcParams.getdefaults()
665+
mpl.rcParams.clear()
666+
assert defaults == mpl.rcParams

0 commit comments

Comments
 (0)