Skip to content

Commit 1c37e78

Browse files
committed
pep8ify: examples/api
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
1 parent 99d3477 commit 1c37e78

35 files changed

+298
-279
lines changed

examples/api/agg_oo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
fig = Figure()
1010
canvas = FigureCanvas(fig)
1111
ax = fig.add_subplot(111)
12-
ax.plot([1,2,3])
12+
ax.plot([1, 2, 3])
1313
ax.set_title('hi mom')
1414
ax.grid(True)
1515
ax.set_xlabel('time')

examples/api/barchart_demo.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
N = 5
88
menMeans = (20, 35, 30, 35, 27)
9-
menStd = (2, 3, 4, 1, 2)
9+
menStd = (2, 3, 4, 1, 2)
1010

1111
ind = np.arange(N) # the x locations for the groups
1212
width = 0.35 # the width of the bars
@@ -15,22 +15,23 @@
1515
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
1616

1717
womenMeans = (25, 32, 34, 20, 25)
18-
womenStd = (3, 5, 2, 3, 3)
19-
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
18+
womenStd = (3, 5, 2, 3, 3)
19+
rects2 = ax.bar(ind + width, womenMeans, width, color='y', yerr=womenStd)
2020

2121
# add some text for labels, title and axes ticks
2222
ax.set_ylabel('Scores')
2323
ax.set_title('Scores by group and gender')
24-
ax.set_xticks(ind+width)
25-
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )
24+
ax.set_xticks(ind + width)
25+
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
26+
27+
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
2628

27-
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
2829

2930
def autolabel(rects):
3031
# attach some text labels
3132
for rect in rects:
3233
height = rect.get_height()
33-
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
34+
ax.text(rect.get_x() + rect.get_width()/2., 1.05*height, '%d' % int(height),
3435
ha='center', va='bottom')
3536

3637
autolabel(rects1)

examples/api/bbox_intersect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
color = 'r'
1515
else:
1616
color = 'b'
17-
plt.plot(vertices[:,0], vertices[:,1], color=color)
17+
plt.plot(vertices[:, 0], vertices[:, 1], color=color)
1818

1919
plt.show()

examples/api/collections_demo.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
# Make some spirals
2929
r = np.array(range(nverts))
30-
theta = np.array(range(nverts)) * (2*np.pi)/(nverts-1)
30+
theta = np.array(range(nverts))*2*np.pi/(nverts - 1)
3131
xx = r * np.sin(theta)
3232
yy = r * np.cos(theta)
33-
spiral = list(zip(xx,yy))
33+
spiral = list(zip(xx, yy))
3434

3535
# Make some offsets
3636
rs = np.random.RandomState([12345678])
@@ -39,27 +39,28 @@
3939
xyo = list(zip(xo, yo))
4040

4141
# Make a list of colors cycling through the rgbcmyk series.
42-
colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')]
42+
colors = [colorConverter.to_rgba(c)
43+
for c in ('r', 'g', 'b', 'c', 'y', 'm', 'k')]
4344

44-
fig, axes = plt.subplots(2,2)
45-
((ax1, ax2), (ax3, ax4)) = axes # unpack the axes
45+
fig, axes = plt.subplots(2, 2)
46+
((ax1, ax2), (ax3, ax4)) = axes # unpack the axes
4647

4748

4849
col = collections.LineCollection([spiral], offsets=xyo,
49-
transOffset=ax1.transData)
50+
transOffset=ax1.transData)
5051
trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
5152
col.set_transform(trans) # the points to pixels transform
52-
# Note: the first argument to the collection initializer
53-
# must be a list of sequences of x,y tuples; we have only
54-
# one sequence, but we still have to put it in a list.
53+
# Note: the first argument to the collection initializer
54+
# must be a list of sequences of x,y tuples; we have only
55+
# one sequence, but we still have to put it in a list.
5556
ax1.add_collection(col, autolim=True)
56-
# autolim=True enables autoscaling. For collections with
57-
# offsets like this, it is neither efficient nor accurate,
58-
# but it is good enough to generate a plot that you can use
59-
# as a starting point. If you know beforehand the range of
60-
# x and y that you want to show, it is better to set them
61-
# explicitly, leave out the autolim kwarg (or set it to False),
62-
# and omit the 'ax1.autoscale_view()' call below.
57+
# autolim=True enables autoscaling. For collections with
58+
# offsets like this, it is neither efficient nor accurate,
59+
# but it is good enough to generate a plot that you can use
60+
# as a starting point. If you know beforehand the range of
61+
# x and y that you want to show, it is better to set them
62+
# explicitly, leave out the autolim kwarg (or set it to False),
63+
# and omit the 'ax1.autoscale_view()' call below.
6364

6465
# Make a transform for the line segments such that their size is
6566
# given in points:
@@ -71,7 +72,7 @@
7172

7273
# The same data as above, but fill the curves.
7374
col = collections.PolyCollection([spiral], offsets=xyo,
74-
transOffset=ax2.transData)
75+
transOffset=ax2.transData)
7576
trans = transforms.Affine2D().scale(fig.dpi/72.0)
7677
col.set_transform(trans) # the points to pixels transform
7778
ax2.add_collection(col, autolim=True)
@@ -84,9 +85,9 @@
8485
# 7-sided regular polygons
8586

8687
col = collections.RegularPolyCollection(7,
87-
sizes = np.fabs(xx)*10.0, offsets=xyo,
88+
sizes=np.fabs(xx) * 10.0, offsets=xyo,
8889
transOffset=ax3.transData)
89-
trans = transforms.Affine2D().scale(fig.dpi/72.0)
90+
trans = transforms.Affine2D().scale(fig.dpi / 72.0)
9091
col.set_transform(trans) # the points to pixels transform
9192
ax3.add_collection(col, autolim=True)
9293
col.set_color(colors)
@@ -104,7 +105,7 @@
104105

105106
yy = np.linspace(0, 2*np.pi, nverts)
106107
ym = np.amax(yy)
107-
xx = (0.2 + (ym-yy)/ym)**2 * np.cos(yy-0.4) * 0.5
108+
xx = (0.2 + (ym - yy)/ym)**2 * np.cos(yy - 0.4)*0.5
108109
segs = []
109110
for i in range(ncurves):
110111
xxx = xx + 0.02*rs.randn(nverts)
@@ -123,5 +124,3 @@
123124

124125

125126
plt.show()
126-
127-

examples/api/colorbar_only.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import matplotlib as mpl
77

88
# Make a figure and axes with dimensions as desired.
9-
fig = pyplot.figure(figsize=(8,3))
9+
fig = pyplot.figure(figsize=(8, 3))
1010
ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15])
1111
ax2 = fig.add_axes([0.05, 0.475, 0.9, 0.15])
1212
ax3 = fig.add_axes([0.05, 0.15, 0.9, 0.15])
@@ -22,8 +22,8 @@
2222
# following gives a basic continuous colorbar with ticks
2323
# and labels.
2424
cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap,
25-
norm=norm,
26-
orientation='horizontal')
25+
norm=norm,
26+
orientation='horizontal')
2727
cb1.set_label('Some Units')
2828

2929
# The second example illustrates the use of a ListedColormap, a
@@ -39,36 +39,36 @@
3939
bounds = [1, 2, 4, 7, 8]
4040
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
4141
cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap,
42-
norm=norm,
43-
# to use 'extend', you must
44-
# specify two extra boundaries:
45-
boundaries=[0]+bounds+[13],
46-
extend='both',
47-
ticks=bounds, # optional
48-
spacing='proportional',
49-
orientation='horizontal')
42+
norm=norm,
43+
# to use 'extend', you must
44+
# specify two extra boundaries:
45+
boundaries=[0] + bounds + [13],
46+
extend='both',
47+
ticks=bounds, # optional
48+
spacing='proportional',
49+
orientation='horizontal')
5050
cb2.set_label('Discrete intervals, some other units')
5151

5252
# The third example illustrates the use of custom length colorbar
5353
# extensions, used on a colorbar with discrete intervals.
5454
cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.],
55-
[1., .8, 0.], [1., .4, 0.]])
55+
[1., .8, 0.], [1., .4, 0.]])
5656
cmap.set_over((1., 0., 0.))
5757
cmap.set_under((0., 0., 1.))
5858

5959
bounds = [-1., -.5, 0., .5, 1.]
6060
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
6161
cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap,
62-
norm=norm,
63-
boundaries=[-10]+bounds+[10],
64-
extend='both',
65-
# Make the length of each extension
66-
# the same as the length of the
67-
# interior colors:
68-
extendfrac='auto',
69-
ticks=bounds,
70-
spacing='uniform',
71-
orientation='horizontal')
62+
norm=norm,
63+
boundaries=[-10] + bounds + [10],
64+
extend='both',
65+
# Make the length of each extension
66+
# the same as the length of the
67+
# interior colors:
68+
extendfrac='auto',
69+
ticks=bounds,
70+
spacing='uniform',
71+
orientation='horizontal')
7272
cb3.set_label('Custom extension lengths, some other units')
7373

7474
pyplot.show()

examples/api/compound_path.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
vertices = []
1313
codes = []
1414

15-
codes = [Path.MOVETO] + [Path.LINETO]*3 + [Path.CLOSEPOLY]
16-
vertices = [(1,1), (1,2), (2, 2), (2, 1), (0,0)]
15+
codes = [Path.MOVETO] + [Path.LINETO]* 3 + [Path.CLOSEPOLY]
16+
vertices = [(1, 1), (1, 2), (2, 2), (2, 1), (0, 0)]
1717

1818
codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
19-
vertices += [(4,4), (5,5), (5, 4), (0,0)]
19+
vertices += [(4, 4), (5, 5), (5, 4), (0, 0)]
2020

2121
vertices = np.array(vertices, float)
2222
path = Path(vertices, codes)

examples/api/custom_projection_example.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
# code used by a number of projections with similar characteristics
1919
# (see geo.py).
2020

21+
2122
class HammerAxes(Axes):
23+
2224
"""
2325
A custom class for the Aitoff-Hammer projection, an equal-area map
2426
projection.
@@ -156,16 +158,16 @@ def _set_lim_and_transforms(self):
156158
# (1, ymax). The goal of these transforms is to go from that
157159
# space to display space. The tick labels will be offset 4
158160
# pixels from the edge of the axes ellipse.
159-
yaxis_stretch = Affine2D().scale(np.pi * 2.0, 1.0).translate(-np.pi, 0.0)
161+
yaxis_stretch = Affine2D().scale(2*np.pi, 1.0).translate(-np.pi, 0.0)
160162
yaxis_space = Affine2D().scale(1.0, 1.1)
161163
self._yaxis_transform = \
162164
yaxis_stretch + \
163165
self.transData
164166
yaxis_text_base = \
165167
yaxis_stretch + \
166168
self.transProjection + \
167-
(yaxis_space + \
168-
self.transAffine + \
169+
(yaxis_space +
170+
self.transAffine +
169171
self.transAxes)
170172
self._yaxis_text1_transform = \
171173
yaxis_text_base + \
@@ -174,12 +176,12 @@ def _set_lim_and_transforms(self):
174176
yaxis_text_base + \
175177
Affine2D().translate(8.0, 0.0)
176178

177-
def get_xaxis_transform(self,which='grid'):
179+
def get_xaxis_transform(self, which='grid'):
178180
"""
179181
Override this method to provide a transformation for the
180182
x-axis grid and ticks.
181183
"""
182-
assert which in ['tick1','tick2','grid']
184+
assert which in ['tick1', 'tick2', 'grid']
183185
return self._xaxis_transform
184186

185187
def get_xaxis_text1_transform(self, pixelPad):
@@ -200,12 +202,12 @@ def get_xaxis_text2_transform(self, pixelPad):
200202
"""
201203
return self._xaxis_text2_transform, 'top', 'center'
202204

203-
def get_yaxis_transform(self,which='grid'):
205+
def get_yaxis_transform(self, which='grid'):
204206
"""
205207
Override this method to provide a transformation for the
206208
y-axis grid and ticks.
207209
"""
208-
assert which in ['tick1','tick2','grid']
210+
assert which in ['tick1', 'tick2', 'grid']
209211
return self._yaxis_transform
210212

211213
def get_yaxis_text1_transform(self, pixelPad):
@@ -238,8 +240,8 @@ def _gen_axes_patch(self):
238240
return Circle((0.5, 0.5), 0.5)
239241

240242
def _gen_axes_spines(self):
241-
return {'custom_hammer':mspines.Spine.circular_spine(self,
242-
(0.5, 0.5), 0.5)}
243+
return {'custom_hammer': mspines.Spine.circular_spine(self,
244+
(0.5, 0.5), 0.5)}
243245

244246
# Prevent the user from applying scales to one or both of the
245247
# axes. In this particular case, scaling the axes wouldn't make
@@ -284,10 +286,12 @@ def format_coord(self, lon, lat):
284286
return '%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(lon), ew)
285287

286288
class DegreeFormatter(Formatter):
289+
287290
"""
288291
This is a custom formatter that converts the native unit of
289292
radians into (truncated) degrees and adds a degree symbol.
290293
"""
294+
291295
def __init__(self, round_to=1.0):
292296
self._round_to = round_to
293297

@@ -369,16 +373,20 @@ def can_zoom(self):
369373
Return True if this axes support the zoom box
370374
"""
371375
return False
376+
372377
def start_pan(self, x, y, button):
373378
pass
379+
374380
def end_pan(self):
375381
pass
382+
376383
def drag_pan(self, button, key, x, y):
377384
pass
378385

379386
# Now, the transforms themselves.
380387

381388
class HammerTransform(Transform):
389+
382390
"""
383391
The base Hammer transform.
384392
"""
@@ -394,7 +402,7 @@ def transform_non_affine(self, ll):
394402
The input and output are Nx2 numpy arrays.
395403
"""
396404
longitude = ll[:, 0:1]
397-
latitude = ll[:, 1:2]
405+
latitude = ll[:, 1:2]
398406

399407
# Pre-compute some values
400408
half_long = longitude / 2.0
@@ -417,13 +425,13 @@ def transform_path_non_affine(self, path):
417425
ipath = path.interpolated(path._interpolation_steps)
418426
return Path(self.transform(ipath.vertices), ipath.codes)
419427
transform_path_non_affine.__doc__ = \
420-
Transform.transform_path_non_affine.__doc__
428+
Transform.transform_path_non_affine.__doc__
421429

422430
if matplotlib.__version__ < '1.2':
423431
# Note: For compatibility with matplotlib v1.1 and older, you'll
424432
# need to explicitly implement a ``transform`` method as well.
425433
# Otherwise a ``NotImplementedError`` will be raised. This isn't
426-
# necessary for v1.2 and newer, however.
434+
# necessary for v1.2 and newer, however.
427435
transform = transform_non_affine
428436

429437
# Similarly, we need to explicitly override ``transform_path`` if
@@ -449,12 +457,12 @@ def transform_non_affine(self, xy):
449457
quarter_x = 0.25 * x
450458
half_y = 0.5 * y
451459
z = np.sqrt(1.0 - quarter_x*quarter_x - half_y*half_y)
452-
longitude = 2 * np.arctan((z*x) / (2.0 * (2.0*z*z - 1.0)))
460+
longitude = 2*np.arctan((z*x)/(2.0*(2.0*z*z - 1.0)))
453461
latitude = np.arcsin(y*z)
454462
return np.concatenate((longitude, latitude), 1)
455463
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
456464

457-
# As before, we need to implement the "transform" method for
465+
# As before, we need to implement the "transform" method for
458466
# compatibility with matplotlib v1.1 and older.
459467
if matplotlib.__version__ < '1.2':
460468
transform = transform_non_affine
@@ -476,4 +484,3 @@ def inverted(self):
476484
plt.grid(True)
477485

478486
plt.show()
479-

0 commit comments

Comments
 (0)