Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc95a3a

Browse files
committed
Deprecation warning for cmap_d.
1 parent67ffc66 commitcc95a3a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

‎lib/matplotlib/cm.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,33 @@ def _gen_cmap_d():
7171
returncmap_d
7272

7373

74+
class_DeprecatedCmapDict(dict):
75+
def__getitem__(self,key):
76+
self._warn_deprecated()
77+
returndict.__getitem__(self,key)
78+
79+
def__setitem__(self,key,val):
80+
self._warn_deprecated()
81+
dict.__setitem__(self,key,val)
82+
83+
defget(self,key,default=None):
84+
self._warn_deprecated()
85+
returndict.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()
7598
locals().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 ...

‎lib/matplotlib/tests/test_colors.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ def test_colormap_global_set_warn():
126126
plt.register_cmap(cmap=orig_cmap)
127127

128128

129+
deftest_colormap_dict_deprecate():
130+
# Make sure we warn on get and set access into cmap_d
131+
withpytest.warns(cbook.MatplotlibDeprecationWarning,
132+
match="The global colormaps dictionary is no longer"):
133+
cm=plt.cm.cmap_d['viridis']
134+
135+
withpytest.warns(cbook.MatplotlibDeprecationWarning,
136+
match="The global colormaps dictionary is no longer"):
137+
plt.cm.cmap_d['test']=cm
138+
139+
129140
deftest_colormap_copy():
130141
cm=plt.cm.Reds
131142
cm_copy=copy.copy(cm)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp