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

Commitf2f5ca2

Browse files
committed
ENH: add method to un-register a color map
1 parent8167da6 commitf2f5ca2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Add ``cm.unregister_cmap`` function
3+
-----------------------------------
4+
5+
`.cm.unregister_cmap` allows users to remove a color map that they
6+
have previously registered.

‎lib/matplotlib/cm.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@ def get_cmap(name=None, lut=None):
144144
returncmap_d[name]._resample(lut)
145145

146146

147+
defunregister_cmap(name):
148+
"""
149+
Remove a colormap recognized by :func:`get_cmap`.
150+
151+
You may not remove built in color maps.
152+
153+
If the named color map is not registered, returns with no error, raises
154+
if you try to de-register a default color map.
155+
156+
Raises
157+
------
158+
ValueError
159+
If you
160+
"""
161+
ifnamenotincmap_d:
162+
return
163+
ifnameinglobals():
164+
raiseValueError(f"Can not unregister{name} which is a builtin "
165+
"color map.")
166+
cmap_d.pop(name)
167+
168+
147169
classScalarMappable:
148170
"""
149171
This is a mixin class to support scalar data to RGBA mapping.

‎lib/matplotlib/tests/test_cm.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ def test_register_cmap():
1313

1414
withpytest.warns(UserWarning):
1515
mcm.register_cmap('viridis'[::-1],mcm.get_cmap('viridis'))
16+
17+
18+
mcm.unregister_cmap('viridis'[::-1])
19+
withpytest.raises(ValueError):
20+
mcm.get_cmap('viridis'[::-1])
21+
# test that second time is error free
22+
mcm.unregister_cmap('viridis'[::-1])
23+
24+
25+
deftest_unregister_cmap():
26+
withpytest.raises(ValueError):
27+
mcm.unregister_cmap('viridis')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp