Skip to content

Commit cc7fc7f

Browse files
committed
pep8 fix e2* in examples dir part 1/2
1 parent 2f5b1e1 commit cc7fc7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+184
-183
lines changed

examples/animation/double_pendulum_animated.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ def derivs(state, t):
1919
dydx = np.zeros_like(state)
2020
dydx[0] = state[1]
2121

22-
del_ = state[2]-state[0]
23-
den1 = (M1+M2)*L1 - M2*L1*cos(del_)*cos(del_)
22+
del_ = state[2] - state[0]
23+
den1 = (M1 + M2)*L1 - M2*L1*cos(del_)*cos(del_)
2424
dydx[1] = (M2*L1*state[1]*state[1]*sin(del_)*cos(del_)
2525
+ M2*G*sin(state[2])*cos(del_)
2626
+ M2*L2*state[3]*state[3]*sin(del_)
27-
- (M1+M2)*G*sin(state[0]))/den1
27+
- (M1 + M2)*G*sin(state[0]))/den1
2828

2929
dydx[2] = state[3]
3030

3131
den2 = (L2/L1)*den1
3232
dydx[3] = (-M2*L2*state[3]*state[3]*sin(del_)*cos(del_)
33-
+ (M1+M2)*G*sin(state[0])*cos(del_)
34-
- (M1+M2)*L1*state[1]*state[1]*sin(del_)
35-
- (M1+M2)*G*sin(state[2]))/den2
33+
+ (M1 + M2)*G*sin(state[0])*cos(del_)
34+
- (M1 + M2)*L1*state[1]*state[1]*sin(del_)
35+
- (M1 + M2)*G*sin(state[2]))/den2
3636

3737
return dydx
3838

examples/animation/simple_3danim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def Gen_RandLine(length, dims=2):
2222
# subtraction by 0.5 is to change the range to [-0.5, 0.5]
2323
# to allow a line to move backwards.
2424
step = ((np.random.rand(dims) - 0.5) * 0.1)
25-
lineData[:, index] = lineData[:, index-1] + step
25+
lineData[:, index] = lineData[:, index - 1] + step
2626

2727
return lineData
2828

examples/axes_grid/demo_floating_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ def setup_axes3(fig, rect):
130130

131131
ax2, aux_ax2 = setup_axes2(fig, 132)
132132
theta = np.random.rand(10)*.5*np.pi
133-
radius = np.random.rand(10)+1.
133+
radius = np.random.rand(10) + 1.
134134
aux_ax2.scatter(theta, radius)
135135

136136
ax3, aux_ax3 = setup_axes3(fig, 133)
137137

138-
theta = (8 + np.random.rand(10)*(14-8))*15. # in degrees
138+
theta = (8 + np.random.rand(10)*(14 - 8))*15. # in degrees
139139
radius = np.random.rand(10)*14000.
140140
aux_ax3.scatter(theta, radius)
141141

examples/event_handling/data_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def onpress(self, event):
2323
else: inc = -1
2424

2525
self.lastind += inc
26-
self.lastind = np.clip(self.lastind, 0, len(xs)-1)
26+
self.lastind = np.clip(self.lastind, 0, len(xs) - 1)
2727
self.update()
2828

2929
def onpick(self, event):
@@ -37,7 +37,7 @@ def onpick(self, event):
3737
x = event.mouseevent.xdata
3838
y = event.mouseevent.ydata
3939

40-
distances = np.hypot(x-xs[event.ind], y-ys[event.ind])
40+
distances = np.hypot(x - xs[event.ind], y - ys[event.ind])
4141
indmin = distances.argmin()
4242
dataind = event.ind[indmin]
4343

examples/event_handling/idle_and_timeout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def on_idle(event):
2222
on_idle.count += 1
2323
print('idle', on_idle.count)
24-
line1.set_ydata(np.sin(2*np.pi*t*(N-on_idle.count)/float(N)))
24+
line1.set_ydata(np.sin(2*np.pi*t*(N - on_idle.count)/float(N)))
2525
event.canvas.draw()
2626
# test boolean return removal
2727
if on_idle.count == N:

examples/event_handling/path_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_ind_under_point(self, event):
8080
xy = np.asarray(self.pathpatch.get_path().vertices)
8181
xyt = self.pathpatch.get_transform().transform(xy)
8282
xt, yt = xyt[:, 0], xyt[:, 1]
83-
d = np.sqrt((xt-event.x)**2 + (yt-event.y)**2)
83+
d = np.sqrt((xt - event.x)**2 + (yt - event.y)**2)
8484
ind = d.argmin()
8585

8686
if d[ind] >= self.epsilon:

examples/event_handling/pick_event_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def line_picker(line, mouseevent):
120120
xdata = line.get_xdata()
121121
ydata = line.get_ydata()
122122
maxd = 0.05
123-
d = np.sqrt((xdata-mouseevent.xdata)**2. + (ydata-mouseevent.ydata)**2.)
123+
d = np.sqrt((xdata - mouseevent.xdata)**2. + (ydata - mouseevent.ydata)**2.)
124124

125125
ind = np.nonzero(np.less_equal(d, maxd))
126126
if len(ind):

examples/event_handling/pick_event_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def onpick(event):
2525

2626
figi = plt.figure()
2727
for subplotnum, dataind in enumerate(event.ind):
28-
ax = figi.add_subplot(N, 1, subplotnum+1)
28+
ax = figi.add_subplot(N, 1, subplotnum + 1)
2929
ax.plot(X[dataind])
3030
ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
3131
transform=ax.transAxes, va='top')

examples/event_handling/pipong.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ def update(self, pads):
8080
self.vy *= 1.2 * pad.signy
8181
fudge = .001
8282
# probably cleaner with something like...if not self.field.contains(self.x, self.y):
83-
if self.x < 0+fudge:
83+
if self.x < 0 + fudge:
8484
#print("player A loses")
8585
pads[1].score += 1;
8686
self._reset(pads[0])
8787
return True
88-
if self.x > 7-fudge:
88+
if self.x > 7 - fudge:
8989
#print("player B loses")
9090
pads[0].score += 1;
9191
self._reset(pads[1])
9292
return True
93-
if self.y < -1+fudge or self.y > 1-fudge:
93+
if self.y < -1 + fudge or self.y > 1 - fudge:
9494
self.vy *= -1.0
9595
# add some randomness, just to make it interesting
9696
self.vy -= (randn()/300.0 + 1/300.0) * np.sign(self.vy)
@@ -166,10 +166,10 @@ def draw(self, evt):
166166

167167
# show the distractors
168168
if self.distract:
169-
self.line.set_ydata(np.sin(self.x+self.cnt/self.res))
170-
self.line2.set_ydata(np.cos(self.x-self.cnt/self.res))
171-
self.line3.set_ydata(np.tan(self.x+self.cnt/self.res))
172-
self.line4.set_ydata(np.tan(self.x-self.cnt/self.res))
169+
self.line.set_ydata(np.sin(self.x + self.cnt/self.res))
170+
self.line2.set_ydata(np.cos(self.x - self.cnt/self.res))
171+
self.line3.set_ydata(np.tan(self.x + self.cnt/self.res))
172+
self.line4.set_ydata(np.tan(self.x - self.cnt/self.res))
173173
draw_artist(self.line)
174174
draw_artist(self.line2)
175175
draw_artist(self.line3)
@@ -224,7 +224,7 @@ def key_press(self, event):
224224
if event.key == 'e':
225225
self.pads[0].y += .1
226226
if self.pads[0].y > 1 - .3:
227-
self.pads[0].y = 1-.3
227+
self.pads[0].y = 1 - .3
228228
if event.key == 'd':
229229
self.pads[0].y -= .1
230230
if self.pads[0].y < -1:
@@ -233,7 +233,7 @@ def key_press(self, event):
233233
if event.key == 'i':
234234
self.pads[1].y += .1
235235
if self.pads[1].y > 1 - .3:
236-
self.pads[1].y = 1-.3
236+
self.pads[1].y = 1 - .3
237237
if event.key == 'k':
238238
self.pads[1].y -= .1
239239
if self.pads[1].y < -1:

examples/event_handling/poly_editor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_ind_under_point(self, event):
7070
xy = np.asarray(self.poly.xy)
7171
xyt = self.poly.get_transform().transform(xy)
7272
xt, yt = xyt[:, 0], xyt[:, 1]
73-
d = np.sqrt((xt-event.x)**2 + (yt-event.y)**2)
73+
d = np.sqrt((xt - event.x)**2 + (yt - event.y)**2)
7474
indseq = np.nonzero(np.equal(d, np.amin(d)))[0]
7575
ind = indseq[0]
7676

@@ -107,9 +107,9 @@ def key_press_callback(self, event):
107107
elif event.key == 'i':
108108
xys = self.poly.get_transform().transform(self.poly.xy)
109109
p = event.x, event.y # display coords
110-
for i in range(len(xys)-1):
110+
for i in range(len(xys) - 1):
111111
s0 = xys[i]
112-
s1 = xys[i+1]
112+
s1 = xys[i + 1]
113113
d = dist_point_to_segment(p, s0, s1)
114114
if d <= self.epsilon:
115115
self.poly.xy = np.array(

examples/event_handling/pong_gtk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def start_anim(event):
3232
tstart = time.time()
3333
plt.grid() # to ensure proper background restore
3434
plt.show()
35-
print('FPS:' , animation.cnt/(time.time()-tstart))
35+
print('FPS:', animation.cnt/(time.time() - tstart))

examples/event_handling/zoom_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
def onpress(event):
3131
if event.button != 1: return
3232
x, y = event.xdata, event.ydata
33-
axzoom.set_xlim(x-0.1, x+0.1)
34-
axzoom.set_ylim(y-0.1, y+0.1)
33+
axzoom.set_xlim(x - 0.1, x + 0.1)
34+
axzoom.set_ylim(y - 0.1, y + 0.1)
3535
figzoom.canvas.draw()
3636

3737
figsrc.canvas.mpl_connect('button_press_event', onpress)

examples/misc/ftface_props.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
font = ft.FT2Font(fname)
1919

20-
print('Num faces :', font.num_faces) # number of faces in file
21-
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
22-
print('Family name :', font.family_name) # face family name
23-
print('Syle name :', font.style_name) # face syle name
24-
print('PS name :', font.postscript_name) # the postscript name
25-
print('Num fixed :', font.num_fixed_sizes) # number of embedded bitmap in face
20+
print('Num faces :', font.num_faces) # number of faces in file
21+
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
22+
print('Family name :', font.family_name) # face family name
23+
print('Syle name :', font.style_name) # face syle name
24+
print('PS name :', font.postscript_name) # the postscript name
25+
print('Num fixed :', font.num_fixed_sizes) # number of embedded bitmap in face
2626

2727
# the following are only available if face.scalable
2828
if font.scalable:

examples/misc/longshort.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535

3636
# long appl, short goog
37-
g = r.gains1-r.gains2
38-
tr = (1+g).cumprod() # the total return
37+
g = r.gains1 - r.gains2
38+
tr = (1 + g).cumprod() # the total return
3939

4040
# plot the return
4141
fig, ax = plt.subplots()

examples/misc/rc_traits.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
flexible_false_trait = traits.Trait(False, flexible_true_trait)
2020

2121
colors = {
22-
'c' : '#00bfbf',
23-
'b' : '#0000ff',
24-
'g' : '#008000',
25-
'k' : '#000000',
26-
'm' : '#bf00bf',
27-
'r' : '#ff0000',
28-
'w' : '#ffffff',
29-
'y' : '#bfbf00',
30-
'gold' : '#FFD700',
31-
'peachpuff' : '#FFDAB9',
32-
'navajowhite' : '#FFDEAD',
22+
'c': '#00bfbf',
23+
'b': '#0000ff',
24+
'g': '#008000',
25+
'k': '#000000',
26+
'm': '#bf00bf',
27+
'r': '#ff0000',
28+
'w': '#ffffff',
29+
'y': '#bfbf00',
30+
'gold': '#FFD700',
31+
'peachpuff': '#FFDAB9',
32+
'navajowhite': '#FFDEAD',
3333
}
3434

3535

examples/misc/rec_groupby_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def daily_return(prices):
1313
'an array of daily returns from price array'
1414
g = np.zeros_like(prices)
15-
g[1:] = (prices[1:]-prices[:-1])/prices[:-1]
15+
g[1:] = (prices[1:] - prices[:-1])/prices[:-1]
1616
return g
1717

1818

examples/misc/svg_filter_line.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
shadow.set_color("0.2")
3737
# adjust zorder of the shadow lines so that it is drawn below the
3838
# original lines
39-
shadow.set_zorder(l.get_zorder()-0.5)
39+
shadow.set_zorder(l.get_zorder() - 0.5)
4040

4141
# offset transform
4242
ot = mtransforms.offset_copy(l.get_transform(), fig1,
@@ -45,7 +45,7 @@
4545
shadow.set_transform(ot)
4646

4747
# set the id for a later use
48-
shadow.set_gid(l.get_label()+"_shadow")
48+
shadow.set_gid(l.get_label() + "_shadow")
4949

5050

5151
ax.set_xlim(0., 1.)
@@ -77,7 +77,7 @@
7777

7878
for l in [l1, l2]:
7979
# pick up the svg element with given id
80-
shadow = xmlid[l.get_label()+"_shadow"]
80+
shadow = xmlid[l.get_label() + "_shadow"]
8181
# apply shdow filter
8282
shadow.set("filter", 'url(#dropshadow)')
8383

examples/misc/svg_filter_pie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
for w in pies[0]:
3737
# create shadow patch
3838
s = Shadow(w, -0.01, -0.01)
39-
s.set_gid(w.get_gid()+"_shadow")
39+
s.set_gid(w.get_gid() + "_shadow")
4040
s.set_zorder(w.get_zorder() - 0.1)
4141
ax.add_patch(s)
4242

examples/mplot3d/hist3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
hist, xedges, yedges = np.histogram2d(x, y, bins=4)
99

1010
elements = (len(xedges) - 1) * (len(yedges) - 1)
11-
xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25)
11+
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
1212

1313
xpos = xpos.flatten()
1414
ypos = ypos.flatten()

examples/mplot3d/lorenz_attractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from mpl_toolkits.mplot3d import Axes3D
1212

1313

14-
def lorenz(x, y, z, s=10, r=28, b=2.667) :
14+
def lorenz(x, y, z, s=10, r=28, b=2.667):
1515
x_dot = s*(y - x)
1616
y_dot = r*x - y - x*z
1717
z_dot = x*y - b*z
@@ -30,7 +30,7 @@ def lorenz(x, y, z, s=10, r=28, b=2.667) :
3030
xs[0], ys[0], zs[0] = (0., 1., 1.05)
3131

3232
# Stepping through "time".
33-
for i in range(stepCnt) :
33+
for i in range(stepCnt):
3434
# Derivatives of the X, Y, Z state
3535
x_dot, y_dot, z_dot = lorenz(xs[i], ys[i], zs[i])
3636
xs[i + 1] = xs[i] + (x_dot * dt)

examples/mplot3d/scatter3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def randrange(n, vmin, vmax):
7-
return (vmax-vmin)*np.random.rand(n) + vmin
7+
return (vmax - vmin)*np.random.rand(n) + vmin
88

99
fig = plt.figure()
1010
ax = fig.add_subplot(111, projection='3d')

examples/pylab_examples/alignment_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,24 @@
4848
verticalalignment='top',
4949
transform=ax.transAxes)
5050

51-
ax.text(left, 0.5*(bottom+top), 'right center',
51+
ax.text(left, 0.5*(bottom + top), 'right center',
5252
horizontalalignment='right',
5353
verticalalignment='center',
5454
rotation='vertical',
5555
transform=ax.transAxes)
5656

57-
ax.text(left, 0.5*(bottom+top), 'left center',
57+
ax.text(left, 0.5*(bottom + top), 'left center',
5858
horizontalalignment='left',
5959
verticalalignment='center',
6060
rotation='vertical',
6161
transform=ax.transAxes)
6262

63-
ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle',
63+
ax.text(0.5*(left + right), 0.5*(bottom + top), 'middle',
6464
horizontalalignment='center',
6565
verticalalignment='center',
6666
transform=ax.transAxes)
6767

68-
ax.text(right, 0.5*(bottom+top), 'centered',
68+
ax.text(right, 0.5*(bottom + top), 'centered',
6969
horizontalalignment='center',
7070
verticalalignment='center',
7171
rotation='vertical',

examples/pylab_examples/anscombe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def fit(x):
23-
return 3+0.5*x
23+
return 3 + 0.5*x
2424

2525

2626
xfit = array([amin(x), amax(x)])

0 commit comments

Comments
 (0)