@@ -662,21 +662,11 @@ class RcParams(MutableMapping):
662
662
:ref:`customizing-with-matplotlibrc-files`
663
663
"""
664
664
validate = rcsetup ._validators
665
- _namespaces = ("backends" , "lines" , "patches" , "hatches" , "boxplot" , "font" , "text" ,
666
- "latex" , "axes" , "date" , "xtick" , "ytick" , "grid" , "legend" ,
667
- "figure" , "image" , "contour" , "errorbar" , "hist" , "scatter" , "agg" ,
668
- "path" , "savefig" , "tk" , "ps" , "pdf" , "svg" , "pgf" , "docstring" ,
669
- "keymap" , "animation" , "_internal" , "webagg" , "markers" , "pcolor" ,
670
- "pcolormesh" , "patch" , "hatch" , "mathtext" , "polaraxes" , "axes3d" ,
671
- "xaxis" , "yaxis" , "default" )
672
-
673
- _single_key_set = {"backend" , "toolbar" , "interactive" ,
674
- "timezone" , "backend_fallback" }
675
665
676
666
def __init__ (self , * args , ** kwargs ):
677
- self ._namespace_maps = { name : ChainMap ({}) for name in self . _namespaces }
667
+ self ._rcvalues = ChainMap ({})
678
668
self .update (* args , ** kwargs )
679
- self ._new_child ()
669
+ self ._rcvalues . new_child ()
680
670
681
671
@staticmethod
682
672
@functools .lru_cache
@@ -710,25 +700,7 @@ def _set(self, key, val):
710
700
711
701
:meta public:
712
702
"""
713
- keys , depth = self ._split_key (key )
714
- if depth == 1 :
715
- if key in self ._single_key_set :
716
- self ._namespace_maps ["default" ][key ] = val
717
- # Uncomment the following line and remove the raise statement
718
- # to enable setting namespaces.
719
- # else:
720
- # if isinstance(val, dict):
721
- # self._namespace_maps[key] = ChainMap({}, val)
722
- # else:
723
- # raise ValueError(
724
- # f"{key} should be set using a dictionary but found "
725
- # f"{type(val)}")
726
- else :
727
- raise KeyError (
728
- f"{ key } is not a valid rc parameter (see rcParams.keys() for "
729
- f"a list of valid parameters)" )
730
- elif depth == 2 :
731
- self ._namespace_maps [keys [0 ]][keys [1 ]] = val
703
+ self ._rcvalues [key ] = val
732
704
733
705
def _get (self , key ):
734
706
"""
@@ -749,19 +721,7 @@ def _get(self, key):
749
721
750
722
:meta public:
751
723
"""
752
- keys , depth = self ._split_key (key )
753
- if depth == 1 :
754
- if key in self ._single_key_set :
755
- return self ._namespace_maps ["default" ].get (key )
756
- # Uncomment the following line and remove the raise statement
757
- # to enable getting namespace parameters.
758
- # return self._namespace_maps[key]
759
- else :
760
- raise KeyError (
761
- f"{ key } is not a valid rc parameter (see rcParams.keys() for "
762
- f"a list of valid parameters)" )
763
- elif depth == 2 :
764
- return self ._namespace_maps [keys [0 ]].get (keys [1 ])
724
+ return self ._rcvalues [key ]
765
725
766
726
def __setitem__ (self , key , val ):
767
727
try :
@@ -785,8 +745,8 @@ def __setitem__(self, key, val):
785
745
return
786
746
try :
787
747
cval = self .validate [key ](val )
788
- if key in self ._single_key_set :
789
- key = f"default.{ key } "
748
+ # if key in self._single_key_set:
749
+ # key = f"default.{key}"
790
750
except ValueError as ve :
791
751
raise ValueError (f"Key { key } : { ve } " ) from None
792
752
self ._set (key , cval )
@@ -819,21 +779,9 @@ def __getitem__(self, key):
819
779
return self ._get (key )
820
780
821
781
def _get_default (self , key ):
822
- keys , depth = self ._split_key (key )
823
- if depth == 1 :
824
- if key in self ._single_key_set :
825
- return self ._namespace_maps ["default" ].get (key )
826
- # Uncomment the following line and remove the raise statement
827
- # to enable getting namespace parameters.
828
- # return self._namespace_maps[key]
829
- else :
830
- raise KeyError (
831
- f"{ key } is not a valid rc parameter (see rcParams.keys() for "
832
- f"a list of valid parameters)" )
833
- elif depth == 2 :
834
- return self ._namespace_maps [keys [0 ]].maps [- 1 ].get (keys [1 ])
782
+ return self ._rcvalues .maps [- 1 ][key ]
835
783
836
- def getdefault (self , key ):
784
+ def get_default (self , key ):
837
785
if key in _deprecated_map :
838
786
version , alt_key , alt_val , inverse_alt = _deprecated_map [key ]
839
787
_api .warn_deprecated (
@@ -848,7 +796,7 @@ def getdefault(self, key):
848
796
849
797
return self ._get_default (key )
850
798
851
- def getdefaults (self ):
799
+ def get_defaults (self ):
852
800
"""Return default values set during initialization."""
853
801
defaults = self .copy ()
854
802
defaults .clear ()
@@ -860,54 +808,35 @@ def _get_backend_or_none(self):
860
808
return None if backend is rcsetup ._auto_backend_sentinel else backend
861
809
862
810
def __delitem__ (self , key ):
863
- keys , depth = self ._split_key (key )
864
811
try :
865
- if depth == 1 :
866
- if key in self ._single_key_set :
867
- del self ._namespace_maps ["default" ][key ]
868
- else :
869
- raise KeyError
870
- elif depth == 2 :
871
- del self ._namespace_maps [keys [0 ]][keys [1 ]]
812
+ del self ._rcvalues [key ]
872
813
except KeyError as err :
873
814
raise KeyError (
874
815
f"{ key } is not a valid rc parameter (see rcParams.keys() for "
875
816
f"a list of valid parameters)" ) from err
876
817
877
818
def __contains__ (self , key ):
878
- keys , depth = self ._split_key (key )
879
- if depth == 1 :
880
- if key in self ._single_key_set :
881
- return key in self ._namespace_maps ["default" ]
882
- else :
883
- return False
884
- elif depth == 2 :
885
- return any (key in mapping for mapping in self ._namespace_maps )
819
+ return key in self ._rcvalues
886
820
887
821
def __iter__ (self ):
888
822
"""Yield from sorted list of keys"""
889
- keys = (
890
- "." .join ((space , key )) if space != 'default' else key
891
- for space , mapping in self ._namespace_maps .items ()
892
- for key in mapping .keys ()
893
- )
894
823
with _api .suppress_matplotlib_deprecation_warning ():
895
- yield from sorted (keys )
824
+ yield from sorted (self . _rcvalues . keys () )
896
825
897
826
def __len__ (self ):
898
- return sum ( len (mapping ) for mapping in self ._namespace_maps )
827
+ return len (self ._rcvalues )
899
828
900
829
def __repr__ (self ):
901
830
class_name = self .__class__ .__name__
902
831
indent = len (class_name ) + 1
903
832
with _api .suppress_matplotlib_deprecation_warning ():
904
- repr_split = pprint .pformat (dict (self .items ()), indent = 1 ,
833
+ repr_split = pprint .pformat (dict (self ._rcvalues . items ()), indent = 1 ,
905
834
width = 80 - indent ).split ('\n ' )
906
835
repr_indented = ('\n ' + ' ' * indent ).join (repr_split )
907
836
return f'{ class_name } ({ repr_indented } )'
908
837
909
838
def __str__ (self ):
910
- return '\n ' .join (map ('{0[0]}: {0[1]}' .format , sorted (self .items ())))
839
+ return '\n ' .join (map ('{0[0]}: {0[1]}' .format , sorted (self ._rcvalues . items ())))
911
840
912
841
def pop (self , key ):
913
842
keys , depth = self ._split_key (key )
@@ -926,8 +855,7 @@ def popitem(self):
926
855
"popitem is not implemented for RcParams." )
927
856
928
857
def clear (self ):
929
- for namespace in self ._namespace_maps :
930
- self ._namespace_maps [namespace ].clear ()
858
+ self ._rcvalues .clear ()
931
859
932
860
def setdefault (self , key , default = None ):
933
861
"""Insert key with a value of default if key is not in the dictionary.
@@ -1062,8 +990,7 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
1062
990
fname )
1063
991
raise
1064
992
1065
- config = RcParams ()
1066
- config ._parents ()
993
+ config = dict ()
1067
994
1068
995
for key , (val , line , line_no ) in rc_temp .items ():
1069
996
if key in rcsetup ._validators :
@@ -1092,8 +1019,7 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
1092
1019
or from the matplotlib source distribution""" ,
1093
1020
dict (key = key , fname = fname , line_no = line_no ,
1094
1021
line = line .rstrip ('\n ' ), version = version ))
1095
- config ._new_child ()
1096
- return config
1022
+ return RcParams (config )
1097
1023
1098
1024
1099
1025
def rc_params_from_file (fname , fail_on_error = False , use_default_template = True ):
@@ -1117,7 +1043,7 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
1117
1043
return config_from_file
1118
1044
1119
1045
with _api .suppress_matplotlib_deprecation_warning ():
1120
- config = RcParams ({** rcParams .getdefaults (), ** config_from_file })
1046
+ config = RcParams ({** rcParams .get_defaults (), ** config_from_file })
1121
1047
1122
1048
if "" .join (config ['text.latex.preamble' ]):
1123
1049
_log .info ("""
@@ -1137,10 +1063,10 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
1137
1063
# Strip leading comment.
1138
1064
transform = lambda line : line [1 :] if line .startswith ("#" ) else line ,
1139
1065
fail_on_error = True )
1140
- for key in rcsetup ._hardcoded_defaults :
1141
- space , subkey = key .split ("." )
1142
- if not rcParams ._namespace_maps [space ]:
1143
- rcParams ._namespace_maps [space ] = ChainMap ({})
1066
+ # for key in rcsetup._hardcoded_defaults:
1067
+ # space, subkey = key.split(".")
1068
+ # if not rcParams._namespace_maps[space]:
1069
+ # rcParams._namespace_maps[space] = ChainMap({})
1144
1070
rcParams .update (rcsetup ._hardcoded_defaults )
1145
1071
# Normally, the default matplotlibrc file contains *no* entry for backend (the
1146
1072
# corresponding line starts with ##, not #; we fill on _auto_backend_sentinel
@@ -1156,7 +1082,7 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
1156
1082
defaultParams = rcsetup .defaultParams = {
1157
1083
# We want to resolve deprecated rcParams, but not backend...
1158
1084
key : [(rcsetup ._auto_backend_sentinel if key == "backend" else
1159
- rcParams .getdefault (key )),
1085
+ rcParams .get_default (key )),
1160
1086
validator ]
1161
1087
for key , validator in rcsetup ._validators .items ()}
1162
1088
if rcParams ['axes.formatter.use_locale' ]:
@@ -1349,10 +1275,7 @@ def rc_context(rc=None, fname=None):
1349
1275
1350
1276
"""
1351
1277
try :
1352
- for space in rcParams ._namespace_maps .keys ():
1353
- rcParams ._namespace_maps [space ] = rcParams ._namespace_maps [
1354
- space
1355
- ].new_child ()
1278
+ rcParams ._rcvalues = rcParams ._rcvalues .new_child ()
1356
1279
if fname :
1357
1280
rc_file (fname )
1358
1281
if rc :
@@ -1361,7 +1284,7 @@ def rc_context(rc=None, fname=None):
1361
1284
finally :
1362
1285
# Revert to the original rcs.
1363
1286
backend = rcParams ["backend" ]
1364
- rcParams ._parents ()
1287
+ rcParams ._rcvalues = rcParams . _rcvalues . parents
1365
1288
rcParams ["backend" ] = backend
1366
1289
1367
1290
0 commit comments