Skip to content

Commit 705c4f9

Browse files
committed
run autopep8 in examples/api
1 parent 5774fde commit 705c4f9

37 files changed

+349
-324
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: 11 additions & 8 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,23 +15,26 @@
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-
ha='center', va='bottom')
34+
ax.text(
35+
rect.get_x() + rect.get_width() /
36+
2., 1.05 * height, '%d' % int(height),
37+
ha='center', va='bottom')
3538

3639
autolabel(rects1)
3740
autolabel(rects2)

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: 16 additions & 17 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,15 +39,16 @@
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-
trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
50+
transOffset=ax1.transData)
51+
trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0 / 72.0)
5152
col.set_transform(trans) # the points to pixels transform
5253
# Note: the first argument to the collection initializer
5354
# must be a list of sequences of x,y tuples; we have only
@@ -71,8 +72,8 @@
7172

7273
# The same data as above, but fill the curves.
7374
col = collections.PolyCollection([spiral], offsets=xyo,
74-
transOffset=ax2.transData)
75-
trans = transforms.Affine2D().scale(fig.dpi/72.0)
75+
transOffset=ax2.transData)
76+
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)
7879
col.set_color(colors)
@@ -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)
@@ -102,13 +103,13 @@
102103
ncurves = 20
103104
offs = (0.1, 0.0)
104105

105-
yy = np.linspace(0, 2*np.pi, nverts)
106+
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):
110-
xxx = xx + 0.02*rs.randn(nverts)
111-
curve = list(zip(xxx, yy*100))
111+
xxx = xx + 0.02 * rs.randn(nverts)
112+
curve = list(zip(xxx, yy * 100))
112113
segs.append(curve)
113114

114115
col = collections.LineCollection(segs, offsets=offs)
@@ -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: 4 additions & 4 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

18-
codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
19-
vertices += [(4,4), (5,5), (5, 4), (0,0)]
18+
codes += [Path.MOVETO] + [Path.LINETO] * 2 + [Path.CLOSEPOLY]
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: 25 additions & 17 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,17 @@ 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(
162+
np.pi * 2.0, 1.0).translate(-np.pi, 0.0)
160163
yaxis_space = Affine2D().scale(1.0, 1.1)
161164
self._yaxis_transform = \
162165
yaxis_stretch + \
163166
self.transData
164167
yaxis_text_base = \
165168
yaxis_stretch + \
166169
self.transProjection + \
167-
(yaxis_space + \
168-
self.transAffine + \
170+
(yaxis_space +
171+
self.transAffine +
169172
self.transAxes)
170173
self._yaxis_text1_transform = \
171174
yaxis_text_base + \
@@ -174,12 +177,12 @@ def _set_lim_and_transforms(self):
174177
yaxis_text_base + \
175178
Affine2D().translate(8.0, 0.0)
176179

177-
def get_xaxis_transform(self,which='grid'):
180+
def get_xaxis_transform(self, which='grid'):
178181
"""
179182
Override this method to provide a transformation for the
180183
x-axis grid and ticks.
181184
"""
182-
assert which in ['tick1','tick2','grid']
185+
assert which in ['tick1', 'tick2', 'grid']
183186
return self._xaxis_transform
184187

185188
def get_xaxis_text1_transform(self, pixelPad):
@@ -200,12 +203,12 @@ def get_xaxis_text2_transform(self, pixelPad):
200203
"""
201204
return self._xaxis_text2_transform, 'top', 'center'
202205

203-
def get_yaxis_transform(self,which='grid'):
206+
def get_yaxis_transform(self, which='grid'):
204207
"""
205208
Override this method to provide a transformation for the
206209
y-axis grid and ticks.
207210
"""
208-
assert which in ['tick1','tick2','grid']
211+
assert which in ['tick1', 'tick2', 'grid']
209212
return self._yaxis_transform
210213

211214
def get_yaxis_text1_transform(self, pixelPad):
@@ -238,8 +241,8 @@ def _gen_axes_patch(self):
238241
return Circle((0.5, 0.5), 0.5)
239242

240243
def _gen_axes_spines(self):
241-
return {'custom_hammer':mspines.Spine.circular_spine(self,
242-
(0.5, 0.5), 0.5)}
244+
return {'custom_hammer': mspines.Spine.circular_spine(self,
245+
(0.5, 0.5), 0.5)}
243246

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

286289
class DegreeFormatter(Formatter):
290+
287291
"""
288292
This is a custom formatter that converts the native unit of
289293
radians into (truncated) degrees and adds a degree symbol.
290294
"""
295+
291296
def __init__(self, round_to=1.0):
292297
self._round_to = round_to
293298

@@ -369,16 +374,20 @@ def can_zoom(self):
369374
Return True if this axes support the zoom box
370375
"""
371376
return False
377+
372378
def start_pan(self, x, y, button):
373379
pass
380+
374381
def end_pan(self):
375382
pass
383+
376384
def drag_pan(self, button, key, x, y):
377385
pass
378386

379387
# Now, the transforms themselves.
380388

381389
class HammerTransform(Transform):
390+
382391
"""
383392
The base Hammer transform.
384393
"""
@@ -394,7 +403,7 @@ def transform_non_affine(self, ll):
394403
The input and output are Nx2 numpy arrays.
395404
"""
396405
longitude = ll[:, 0:1]
397-
latitude = ll[:, 1:2]
406+
latitude = ll[:, 1:2]
398407

399408
# Pre-compute some values
400409
half_long = longitude / 2.0
@@ -417,13 +426,13 @@ def transform_path_non_affine(self, path):
417426
ipath = path.interpolated(path._interpolation_steps)
418427
return Path(self.transform(ipath.vertices), ipath.codes)
419428
transform_path_non_affine.__doc__ = \
420-
Transform.transform_path_non_affine.__doc__
429+
Transform.transform_path_non_affine.__doc__
421430

422431
if matplotlib.__version__ < '1.2':
423432
# Note: For compatibility with matplotlib v1.1 and older, you'll
424433
# need to explicitly implement a ``transform`` method as well.
425434
# Otherwise a ``NotImplementedError`` will be raised. This isn't
426-
# necessary for v1.2 and newer, however.
435+
# necessary for v1.2 and newer, however.
427436
transform = transform_non_affine
428437

429438
# Similarly, we need to explicitly override ``transform_path`` if
@@ -448,13 +457,13 @@ def transform_non_affine(self, xy):
448457

449458
quarter_x = 0.25 * x
450459
half_y = 0.5 * y
451-
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)))
453-
latitude = np.arcsin(y*z)
460+
z = np.sqrt(1.0 - quarter_x * quarter_x - half_y * half_y)
461+
longitude = 2 * np.arctan((z * x) / (2.0 * (2.0 * z * z - 1.0)))
462+
latitude = np.arcsin(y * z)
454463
return np.concatenate((longitude, latitude), 1)
455464
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
456465

457-
# As before, we need to implement the "transform" method for
466+
# As before, we need to implement the "transform" method for
458467
# compatibility with matplotlib v1.1 and older.
459468
if matplotlib.__version__ < '1.2':
460469
transform = transform_non_affine
@@ -476,4 +485,3 @@ def inverted(self):
476485
plt.grid(True)
477486

478487
plt.show()
479-

0 commit comments

Comments
 (0)