Skip to content

Commit f0fb4f7

Browse files
committed
Merge pull request matplotlib#1332 from NelleV/pep8_cm
PEP8 fixes on cm.py
2 parents 687c86e + 16e0376 commit f0fb4f7

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lib/matplotlib/cm.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
# reverse all the colormaps.
2222
# reversed colormaps have '_r' appended to the name.
2323

24+
2425
def _reverser(f):
2526
def freversed(x):
26-
return f(1-x)
27+
return f(1 - x)
2728
return freversed
2829

30+
2931
def revcmap(data):
3032
"""Can only handle specification *data* in dictionary format."""
3133
data_r = {}
@@ -42,6 +44,7 @@ def revcmap(data):
4244
data_r[key] = valnew
4345
return data_r
4446

47+
4548
def _reverse_cmap_spec(spec):
4649
"""Reverses cmap specification *spec*, can handle both dict and tuple
4750
type specs."""
@@ -54,6 +57,7 @@ def _reverse_cmap_spec(spec):
5457
revspec = [(1.0 - a, b) for a, b in revspec]
5558
return revspec
5659

60+
5761
def _generate_cmap(name, lutsize):
5862
"""Generates the requested cmap from it's name *name*. The lut size is
5963
*lutsize*."""
@@ -87,6 +91,7 @@ def _generate_cmap(name, lutsize):
8791

8892
# Continue with definitions ...
8993

94+
9095
def register_cmap(name=None, cmap=None, data=None, lut=None):
9196
"""
9297
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):
125130
cmap = colors.LinearSegmentedColormap(name, data, lut)
126131
cmap_d[name] = cmap
127132

133+
128134
def get_cmap(name=None, lut=None):
129135
"""
130136
Get a colormap instance, defaulting to rc values if *name* is None.
@@ -154,6 +160,7 @@ def get_cmap(name=None, lut=None):
154160

155161
raise ValueError("Colormap %s is not recognized" % name)
156162

163+
157164
class ScalarMappable:
158165
"""
159166
This is a mixin class to support scalar -> RGBA mapping. Handles
@@ -169,14 +176,16 @@ def __init__(self, norm=None, cmap=None):
169176

170177
self.callbacksSM = cbook.CallbackRegistry()
171178

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()
174183

175184
self._A = None
176185
self.norm = norm
177186
self.cmap = get_cmap(cmap)
178187
self.colorbar = None
179-
self.update_dict = {'array':False}
188+
self.update_dict = {'array': False}
180189

181190
def set_colorbar(self, im, ax):
182191
'set the colorbar image and axes associated with mappable'
@@ -219,9 +228,9 @@ def to_rgba(self, x, alpha=None, bytes=False):
219228
if x.dtype == np.uint8:
220229
alpha = np.uint8(alpha * 255)
221230
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
225234
elif x.shape[2] == 4:
226235
xx = x
227236
else:
@@ -267,11 +276,13 @@ def set_clim(self, vmin=None, vmax=None):
267276
ACCEPTS: a length 2 sequence of floats
268277
"""
269278
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):
271280
vmin, vmax = vmin
272281

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
275286
self.changed()
276287

277288
def set_cmap(self, cmap):
@@ -286,7 +297,8 @@ def set_cmap(self, cmap):
286297

287298
def set_norm(self, norm):
288299
'set the normalization instance'
289-
if norm is None: norm = colors.Normalize()
300+
if norm is None:
301+
norm = colors.Normalize()
290302
self.norm = norm
291303
self.changed()
292304

@@ -310,7 +322,6 @@ def autoscale_None(self):
310322
self.norm.autoscale_None(self._A)
311323
self.changed()
312324

313-
314325
def add_checker(self, checker):
315326
"""
316327
Add an entry to a dictionary of boolean flags

0 commit comments

Comments
 (0)