21
21
# reverse all the colormaps.
22
22
# reversed colormaps have '_r' appended to the name.
23
23
24
+
24
25
def _reverser (f ):
25
26
def freversed (x ):
26
- return f (1 - x )
27
+ return f (1 - x )
27
28
return freversed
28
29
30
+
29
31
def revcmap (data ):
30
32
"""Can only handle specification *data* in dictionary format."""
31
33
data_r = {}
@@ -42,6 +44,7 @@ def revcmap(data):
42
44
data_r [key ] = valnew
43
45
return data_r
44
46
47
+
45
48
def _reverse_cmap_spec (spec ):
46
49
"""Reverses cmap specification *spec*, can handle both dict and tuple
47
50
type specs."""
@@ -54,6 +57,7 @@ def _reverse_cmap_spec(spec):
54
57
revspec = [(1.0 - a , b ) for a , b in revspec ]
55
58
return revspec
56
59
60
+
57
61
def _generate_cmap (name , lutsize ):
58
62
"""Generates the requested cmap from it's name *name*. The lut size is
59
63
*lutsize*."""
@@ -87,6 +91,7 @@ def _generate_cmap(name, lutsize):
87
91
88
92
# Continue with definitions ...
89
93
94
+
90
95
def register_cmap (name = None , cmap = None , data = None , lut = None ):
91
96
"""
92
97
Add a colormap to the set recognized by :func:`get_cmap`.
@@ -125,6 +130,7 @@ def register_cmap(name=None, cmap=None, data=None, lut=None):
125
130
cmap = colors .LinearSegmentedColormap (name , data , lut )
126
131
cmap_d [name ] = cmap
127
132
133
+
128
134
def get_cmap (name = None , lut = None ):
129
135
"""
130
136
Get a colormap instance, defaulting to rc values if *name* is None.
@@ -154,6 +160,7 @@ def get_cmap(name=None, lut=None):
154
160
155
161
raise ValueError ("Colormap %s is not recognized" % name )
156
162
163
+
157
164
class ScalarMappable :
158
165
"""
159
166
This is a mixin class to support scalar -> RGBA mapping. Handles
@@ -169,14 +176,16 @@ def __init__(self, norm=None, cmap=None):
169
176
170
177
self .callbacksSM = cbook .CallbackRegistry ()
171
178
172
- if cmap is None : cmap = get_cmap ()
173
- if norm is None : norm = colors .Normalize ()
179
+ if cmap is None :
180
+ cmap = get_cmap ()
181
+ if norm is None :
182
+ norm = colors .Normalize ()
174
183
175
184
self ._A = None
176
185
self .norm = norm
177
186
self .cmap = get_cmap (cmap )
178
187
self .colorbar = None
179
- self .update_dict = {'array' :False }
188
+ self .update_dict = {'array' : False }
180
189
181
190
def set_colorbar (self , im , ax ):
182
191
'set the colorbar image and axes associated with mappable'
@@ -219,9 +228,9 @@ def to_rgba(self, x, alpha=None, bytes=False):
219
228
if x .dtype == np .uint8 :
220
229
alpha = np .uint8 (alpha * 255 )
221
230
m , n = x .shape [:2 ]
222
- xx = np .empty (shape = (m ,n , 4 ), dtype = x .dtype )
223
- xx [:,:, :3 ] = x
224
- xx [:,:, 3 ] = alpha
231
+ xx = np .empty (shape = (m , n , 4 ), dtype = x .dtype )
232
+ xx [:, :, :3 ] = x
233
+ xx [:, :, 3 ] = alpha
225
234
elif x .shape [2 ] == 4 :
226
235
xx = x
227
236
else :
@@ -267,11 +276,13 @@ def set_clim(self, vmin=None, vmax=None):
267
276
ACCEPTS: a length 2 sequence of floats
268
277
"""
269
278
if (vmin is not None and vmax is None and
270
- cbook .iterable (vmin ) and len (vmin )== 2 ):
279
+ cbook .iterable (vmin ) and len (vmin ) == 2 ):
271
280
vmin , vmax = vmin
272
281
273
- if vmin is not None : self .norm .vmin = vmin
274
- if vmax is not None : self .norm .vmax = vmax
282
+ if vmin is not None :
283
+ self .norm .vmin = vmin
284
+ if vmax is not None :
285
+ self .norm .vmax = vmax
275
286
self .changed ()
276
287
277
288
def set_cmap (self , cmap ):
@@ -286,7 +297,8 @@ def set_cmap(self, cmap):
286
297
287
298
def set_norm (self , norm ):
288
299
'set the normalization instance'
289
- if norm is None : norm = colors .Normalize ()
300
+ if norm is None :
301
+ norm = colors .Normalize ()
290
302
self .norm = norm
291
303
self .changed ()
292
304
@@ -310,7 +322,6 @@ def autoscale_None(self):
310
322
self .norm .autoscale_None (self ._A )
311
323
self .changed ()
312
324
313
-
314
325
def add_checker (self , checker ):
315
326
"""
316
327
Add an entry to a dictionary of boolean flags
0 commit comments