Skip to content

Commit d2cdc1e

Browse files
committed
Merge pull request #3181 from thisch/pep8examplesapi
examples/api PEP8 refresh.
2 parents 5774fde + 33b10ba commit d2cdc1e

37 files changed

+355
-331
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)

0 commit comments

Comments
 (0)