File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change @@ -144,6 +144,28 @@ def get_cmap(name=None, lut=None):
144
144
return cmap_d [name ]._resample (lut )
145
145
146
146
147
+ def unregister_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
+ if name not in cmap_d :
162
+ return
163
+ if name in globals ():
164
+ raise ValueError (f"Can not unregister { name } which is a builtin "
165
+ "color map." )
166
+ cmap_d .pop (name )
167
+
168
+
147
169
class ScalarMappable :
148
170
"""
149
171
This is a mixin class to support scalar data to RGBA mapping.
Original file line number Diff line number Diff line change @@ -13,3 +13,15 @@ def test_register_cmap():
13
13
14
14
with pytest .warns (UserWarning ):
15
15
mcm .register_cmap ('viridis' [::- 1 ], mcm .get_cmap ('viridis' ))
16
+
17
+
18
+ mcm .unregister_cmap ('viridis' [::- 1 ])
19
+ with pytest .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
+ def test_unregister_cmap ():
26
+ with pytest .raises (ValueError ):
27
+ mcm .unregister_cmap ('viridis' )
You can’t perform that action at this time.
0 commit comments