Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebde05f

Browse files
committed
Merge pull request matplotlib#3774 from thisch/pep8final
[examples] final pep8 fixes
2 parents f8e829b + 2303939 commit ebde05f

File tree

175 files changed

+898
-826
lines changed

Some content is hidden

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

175 files changed

+898
-826
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/api/scatter_piecharts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737

3838
fig, ax = plt.subplots()
3939
ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0),
40-
s=[s1*s1*_ for _ in sizes], facecolor='blue')
40+
s=[s1*s1*_ for _ in sizes], facecolor='blue')
4141
ax.scatter(np.arange(3), np.arange(3), marker=(xy2, 0),
42-
s=[s2*s2*_ for _ in sizes], facecolor='green')
42+
s=[s2*s2*_ for _ in sizes], facecolor='green')
4343
ax.scatter(np.arange(3), np.arange(3), marker=(xy3, 0),
44-
s=[s3*s3*_ for _ in sizes], facecolor='red')
44+
s=[s3*s3*_ for _ in sizes], facecolor='red')
4545

4646
plt.show()

examples/axes_grid/demo_floating_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import mpl_toolkits.axisartist.angle_helper as angle_helper
55
from matplotlib.projections import PolarAxes
66
from mpl_toolkits.axisartist.grid_finder import (FixedLocator, MaxNLocator,
7-
DictFormatter)
7+
DictFormatter)
88
import matplotlib.pyplot as plt
99

1010

@@ -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: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,45 @@ def __init__(self):
1414
self.text = ax.text(0.05, 0.95, 'selected: none',
1515
transform=ax.transAxes, va='top')
1616
self.selected, = ax.plot([xs[0]], [ys[0]], 'o', ms=12, alpha=0.4,
17-
color='yellow', visible=False)
17+
color='yellow', visible=False)
1818

1919
def onpress(self, event):
20-
if self.lastind is None: return
21-
if event.key not in ('n', 'p'): return
22-
if event.key == 'n': inc = 1
23-
else: inc = -1
20+
if self.lastind is None:
21+
return
22+
if event.key not in ('n', 'p'):
23+
return
24+
if event.key == 'n':
25+
inc = 1
26+
else:
27+
inc = -1
2428

2529
self.lastind += inc
26-
self.lastind = np.clip(self.lastind, 0, len(xs)-1)
30+
self.lastind = np.clip(self.lastind, 0, len(xs) - 1)
2731
self.update()
2832

2933
def onpick(self, event):
3034

31-
if event.artist != line: return True
35+
if event.artist != line:
36+
return True
3237

3338
N = len(event.ind)
34-
if not N: return True
39+
if not N:
40+
return True
3541

3642
# the click locations
3743
x = event.mouseevent.xdata
3844
y = event.mouseevent.ydata
3945

40-
distances = np.hypot(x-xs[event.ind], y-ys[event.ind])
46+
distances = np.hypot(x - xs[event.ind], y - ys[event.ind])
4147
indmin = distances.argmin()
4248
dataind = event.ind[indmin]
4349

4450
self.lastind = dataind
4551
self.update()
4652

4753
def update(self):
48-
if self.lastind is None: return
54+
if self.lastind is None:
55+
return
4956

5057
dataind = self.lastind
5158

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/lasso_demo.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ class Datum(object):
2323
def __init__(self, x, y, include=False):
2424
self.x = x
2525
self.y = y
26-
if include: self.color = self.colorin
27-
else: self.color = self.colorout
26+
if include:
27+
self.color = self.colorin
28+
else:
29+
self.color = self.colorout
2830

2931

3032
class LassoManager(object):
@@ -63,8 +65,10 @@ def callback(self, verts):
6365
del self.lasso
6466

6567
def onpress(self, event):
66-
if self.canvas.widgetlock.locked(): return
67-
if event.inaxes is None: return
68+
if self.canvas.widgetlock.locked():
69+
return
70+
if event.inaxes is None:
71+
return
6872
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
6973
# acquire a lock on the widget drawing
7074
self.canvas.widgetlock(self.lasso)

examples/event_handling/path_editor.py

Lines changed: 23 additions & 12 deletions
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:
@@ -90,33 +90,44 @@ def get_ind_under_point(self, event):
9090

9191
def button_press_callback(self, event):
9292
'whenever a mouse button is pressed'
93-
if not self.showverts: return
94-
if event.inaxes == None: return
95-
if event.button != 1: return
93+
if not self.showverts:
94+
return
95+
if event.inaxes is None:
96+
return
97+
if event.button != 1:
98+
return
9699
self._ind = self.get_ind_under_point(event)
97100

98101
def button_release_callback(self, event):
99102
'whenever a mouse button is released'
100-
if not self.showverts: return
101-
if event.button != 1: return
103+
if not self.showverts:
104+
return
105+
if event.button != 1:
106+
return
102107
self._ind = None
103108

104109
def key_press_callback(self, event):
105110
'whenever a key is pressed'
106-
if not event.inaxes: return
111+
if not event.inaxes:
112+
return
107113
if event.key == 't':
108114
self.showverts = not self.showverts
109115
self.line.set_visible(self.showverts)
110-
if not self.showverts: self._ind = None
116+
if not self.showverts:
117+
self._ind = None
111118

112119
self.canvas.draw()
113120

114121
def motion_notify_callback(self, event):
115122
'on mouse movement'
116-
if not self.showverts: return
117-
if self._ind is None: return
118-
if event.inaxes is None: return
119-
if event.button != 1: return
123+
if not self.showverts:
124+
return
125+
if self._ind is None:
126+
return
127+
if event.inaxes is None:
128+
return
129+
if event.button != 1:
130+
return
120131
x, y = event.xdata, event.ydata
121132

122133
vertices = self.pathpatch.get_path().vertices

examples/event_handling/pick_event_demo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ def line_picker(line, mouseevent):
116116
data coords and attach some extra attributes, pickx and picky
117117
which are the data points that were picked
118118
"""
119-
if mouseevent.xdata is None: return False, dict()
119+
if mouseevent.xdata is None:
120+
return False, dict()
120121
xdata = line.get_xdata()
121122
ydata = line.get_ydata()
122123
maxd = 0.05
123-
d = np.sqrt((xdata-mouseevent.xdata)**2. + (ydata-mouseevent.ydata)**2.)
124+
d = np.sqrt((xdata - mouseevent.xdata)**2. + (ydata - mouseevent.ydata)**2.)
124125

125126
ind = np.nonzero(np.less_equal(d, maxd))
126127
if len(ind):

examples/event_handling/pick_event_demo2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818

1919
def onpick(event):
2020

21-
if event.artist != line: return True
21+
if event.artist != line:
22+
return True
2223

2324
N = len(event.ind)
24-
if not N: return True
25+
if not N:
26+
return True
2527

2628
figi = plt.figure()
2729
for subplotnum, dataind in enumerate(event.ind):
28-
ax = figi.add_subplot(N, 1, subplotnum+1)
30+
ax = figi.add_subplot(N, 1, subplotnum + 1)
2931
ax.plot(X[dataind])
3032
ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
3133
transform=ax.transAxes, va='top')

examples/event_handling/pipong.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,19 @@ def update(self, pads):
7979
self.vx *= 1.2 * pad.signx
8080
self.vy *= 1.2 * pad.signy
8181
fudge = .001
82-
# probably cleaner with something like...if not self.field.contains(self.x, self.y):
83-
if self.x < 0+fudge:
82+
# probably cleaner with something like...
83+
#if not self.field.contains(self.x, self.y):
84+
if self.x < fudge:
8485
#print("player A loses")
85-
pads[1].score += 1;
86+
pads[1].score += 1
8687
self._reset(pads[0])
8788
return True
88-
if self.x > 7-fudge:
89+
if self.x > 7 - fudge:
8990
#print("player B loses")
90-
pads[0].score += 1;
91+
pads[0].score += 1
9192
self._reset(pads[1])
9293
return True
93-
if self.y < -1+fudge or self.y > 1-fudge:
94+
if self.y < -1 + fudge or self.y > 1 - fudge:
9495
self.vy *= -1.0
9596
# add some randomness, just to make it interesting
9697
self.vy -= (randn()/300.0 + 1/300.0) * np.sign(self.vy)
@@ -149,11 +150,11 @@ def __init__(self, ax):
149150
self.pads.append(Pad(pB, padBx, padBy, 'r'))
150151
self.pucks = []
151152
self.i = self.ax.annotate(instructions, (.5, 0.5),
152-
name='monospace',
153-
verticalalignment='center',
154-
horizontalalignment='center',
155-
multialignment='left',
156-
textcoords='axes fraction', animated=True)
153+
name='monospace',
154+
verticalalignment='center',
155+
horizontalalignment='center',
156+
multialignment='left',
157+
textcoords='axes fraction', animated=True)
157158
self.canvas.mpl_connect('key_press_event', self.key_press)
158159

159160
def draw(self, evt):
@@ -166,10 +167,10 @@ def draw(self, evt):
166167

167168
# show the distractors
168169
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))
170+
self.line.set_ydata(np.sin(self.x + self.cnt/self.res))
171+
self.line2.set_ydata(np.cos(self.x - self.cnt/self.res))
172+
self.line3.set_ydata(np.tan(self.x + self.cnt/self.res))
173+
self.line4.set_ydata(np.tan(self.x - self.cnt/self.res))
173174
draw_artist(self.line)
174175
draw_artist(self.line2)
175176
draw_artist(self.line3)
@@ -224,7 +225,7 @@ def key_press(self, event):
224225
if event.key == 'e':
225226
self.pads[0].y += .1
226227
if self.pads[0].y > 1 - .3:
227-
self.pads[0].y = 1-.3
228+
self.pads[0].y = 1 - .3
228229
if event.key == 'd':
229230
self.pads[0].y -= .1
230231
if self.pads[0].y < -1:
@@ -233,7 +234,7 @@ def key_press(self, event):
233234
if event.key == 'i':
234235
self.pads[1].y += .1
235236
if self.pads[1].y > 1 - .3:
236-
self.pads[1].y = 1-.3
237+
self.pads[1].y = 1 - .3
237238
if event.key == 'k':
238239
self.pads[1].y -= .1
239240
if self.pads[1].y < -1:

0 commit comments

Comments
 (0)