File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,10 +71,33 @@ def _gen_cmap_d():
7171 return cmap_d
7272
7373
74+ class _DeprecatedCmapDict (dict ):
75+ def __getitem__ (self , key ):
76+ self ._warn_deprecated ()
77+ return dict .__getitem__ (self , key )
78+
79+ def __setitem__ (self , key , val ):
80+ self ._warn_deprecated ()
81+ dict .__setitem__ (self , key , val )
82+
83+ def get (self , key , default = None ):
84+ self ._warn_deprecated ()
85+ return dict .get (self , key , default )
86+
87+ def _warn_deprecated (self ):
88+ cbook .warn_deprecated (
89+ "3.3" ,
90+ message = "The global colormaps dictionary is no longer "
91+ "considered public API." ,
92+ alternative = "Please use register_cmap() and get_cmap() to "
93+ "access the contents of the dictionary."
94+ )
95+
96+
7497_cmap_d = _gen_cmap_d ()
7598locals ().update (_cmap_d )
7699# This is no longer considered public API
77- cmap_d = _cmap_d
100+ cmap_d = _DeprecatedCmapDict ( _cmap_d )
78101
79102
80103# Continue with definitions ...
Original file line number Diff line number Diff line change @@ -126,6 +126,17 @@ def test_colormap_global_set_warn():
126126 plt .register_cmap (cmap = orig_cmap )
127127
128128
129+ def test_colormap_dict_deprecate ():
130+ # Make sure we warn on get and set access into cmap_d
131+ with pytest .warns (cbook .MatplotlibDeprecationWarning ,
132+ match = "The global colormaps dictionary is no longer" ):
133+ cm = plt .cm .cmap_d ['viridis' ]
134+
135+ with pytest .warns (cbook .MatplotlibDeprecationWarning ,
136+ match = "The global colormaps dictionary is no longer" ):
137+ plt .cm .cmap_d ['test' ] = cm
138+
139+
129140def test_colormap_copy ():
130141 cm = plt .cm .Reds
131142 cm_copy = copy .copy (cm )
You can’t perform that action at this time.
0 commit comments