Skip to content

Commit

Permalink
Merge pull request #3774 from thisch/pep8final
Browse files Browse the repository at this point in the history
[examples] final pep8 fixes
  • Loading branch information
WeatherGod committed Nov 15, 2014
2 parents f8e829b + 2303939 commit ebde05f
Show file tree
Hide file tree
Showing 175 changed files with 898 additions and 826 deletions.
12 changes: 6 additions & 6 deletions examples/animation/double_pendulum_animated.py
Expand Up @@ -19,20 +19,20 @@ def derivs(state, t):
dydx = np.zeros_like(state)
dydx[0] = state[1]

del_ = state[2]-state[0]
den1 = (M1+M2)*L1 - M2*L1*cos(del_)*cos(del_)
del_ = state[2] - state[0]
den1 = (M1 + M2)*L1 - M2*L1*cos(del_)*cos(del_)
dydx[1] = (M2*L1*state[1]*state[1]*sin(del_)*cos(del_)
+ M2*G*sin(state[2])*cos(del_)
+ M2*L2*state[3]*state[3]*sin(del_)
- (M1+M2)*G*sin(state[0]))/den1
- (M1 + M2)*G*sin(state[0]))/den1

dydx[2] = state[3]

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

return dydx

Expand Down
2 changes: 1 addition & 1 deletion examples/animation/simple_3danim.py
Expand Up @@ -22,7 +22,7 @@ def Gen_RandLine(length, dims=2):
# subtraction by 0.5 is to change the range to [-0.5, 0.5]
# to allow a line to move backwards.
step = ((np.random.rand(dims) - 0.5) * 0.1)
lineData[:, index] = lineData[:, index-1] + step
lineData[:, index] = lineData[:, index - 1] + step

return lineData

Expand Down
6 changes: 3 additions & 3 deletions examples/api/scatter_piecharts.py
Expand Up @@ -37,10 +37,10 @@

fig, ax = plt.subplots()
ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0),
s=[s1*s1*_ for _ in sizes], facecolor='blue')
s=[s1*s1*_ for _ in sizes], facecolor='blue')
ax.scatter(np.arange(3), np.arange(3), marker=(xy2, 0),
s=[s2*s2*_ for _ in sizes], facecolor='green')
s=[s2*s2*_ for _ in sizes], facecolor='green')
ax.scatter(np.arange(3), np.arange(3), marker=(xy3, 0),
s=[s3*s3*_ for _ in sizes], facecolor='red')
s=[s3*s3*_ for _ in sizes], facecolor='red')

plt.show()
6 changes: 3 additions & 3 deletions examples/axes_grid/demo_floating_axes.py
Expand Up @@ -4,7 +4,7 @@
import mpl_toolkits.axisartist.angle_helper as angle_helper
from matplotlib.projections import PolarAxes
from mpl_toolkits.axisartist.grid_finder import (FixedLocator, MaxNLocator,
DictFormatter)
DictFormatter)
import matplotlib.pyplot as plt


Expand Down Expand Up @@ -130,12 +130,12 @@ def setup_axes3(fig, rect):

ax2, aux_ax2 = setup_axes2(fig, 132)
theta = np.random.rand(10)*.5*np.pi
radius = np.random.rand(10)+1.
radius = np.random.rand(10) + 1.
aux_ax2.scatter(theta, radius)

ax3, aux_ax3 = setup_axes3(fig, 133)

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

Expand Down
27 changes: 17 additions & 10 deletions examples/event_handling/data_browser.py
Expand Up @@ -14,38 +14,45 @@ def __init__(self):
self.text = ax.text(0.05, 0.95, 'selected: none',
transform=ax.transAxes, va='top')
self.selected, = ax.plot([xs[0]], [ys[0]], 'o', ms=12, alpha=0.4,
color='yellow', visible=False)
color='yellow', visible=False)

def onpress(self, event):
if self.lastind is None: return
if event.key not in ('n', 'p'): return
if event.key == 'n': inc = 1
else: inc = -1
if self.lastind is None:
return
if event.key not in ('n', 'p'):
return
if event.key == 'n':
inc = 1
else:
inc = -1

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

def onpick(self, event):

if event.artist != line: return True
if event.artist != line:
return True

N = len(event.ind)
if not N: return True
if not N:
return True

# the click locations
x = event.mouseevent.xdata
y = event.mouseevent.ydata

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

self.lastind = dataind
self.update()

def update(self):
if self.lastind is None: return
if self.lastind is None:
return

dataind = self.lastind

Expand Down
2 changes: 1 addition & 1 deletion examples/event_handling/idle_and_timeout.py
Expand Up @@ -21,7 +21,7 @@
def on_idle(event):
on_idle.count += 1
print('idle', on_idle.count)
line1.set_ydata(np.sin(2*np.pi*t*(N-on_idle.count)/float(N)))
line1.set_ydata(np.sin(2*np.pi*t*(N - on_idle.count)/float(N)))
event.canvas.draw()
# test boolean return removal
if on_idle.count == N:
Expand Down
12 changes: 8 additions & 4 deletions examples/event_handling/lasso_demo.py
Expand Up @@ -23,8 +23,10 @@ class Datum(object):
def __init__(self, x, y, include=False):
self.x = x
self.y = y
if include: self.color = self.colorin
else: self.color = self.colorout
if include:
self.color = self.colorin
else:
self.color = self.colorout


class LassoManager(object):
Expand Down Expand Up @@ -63,8 +65,10 @@ def callback(self, verts):
del self.lasso

def onpress(self, event):
if self.canvas.widgetlock.locked(): return
if event.inaxes is None: return
if self.canvas.widgetlock.locked():
return
if event.inaxes is None:
return
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
# acquire a lock on the widget drawing
self.canvas.widgetlock(self.lasso)
Expand Down
35 changes: 23 additions & 12 deletions examples/event_handling/path_editor.py
Expand Up @@ -80,7 +80,7 @@ def get_ind_under_point(self, event):
xy = np.asarray(self.pathpatch.get_path().vertices)
xyt = self.pathpatch.get_transform().transform(xy)
xt, yt = xyt[:, 0], xyt[:, 1]
d = np.sqrt((xt-event.x)**2 + (yt-event.y)**2)
d = np.sqrt((xt - event.x)**2 + (yt - event.y)**2)
ind = d.argmin()

if d[ind] >= self.epsilon:
Expand All @@ -90,33 +90,44 @@ def get_ind_under_point(self, event):

def button_press_callback(self, event):
'whenever a mouse button is pressed'
if not self.showverts: return
if event.inaxes == None: return
if event.button != 1: return
if not self.showverts:
return
if event.inaxes is None:
return
if event.button != 1:
return
self._ind = self.get_ind_under_point(event)

def button_release_callback(self, event):
'whenever a mouse button is released'
if not self.showverts: return
if event.button != 1: return
if not self.showverts:
return
if event.button != 1:
return
self._ind = None

def key_press_callback(self, event):
'whenever a key is pressed'
if not event.inaxes: return
if not event.inaxes:
return
if event.key == 't':
self.showverts = not self.showverts
self.line.set_visible(self.showverts)
if not self.showverts: self._ind = None
if not self.showverts:
self._ind = None

self.canvas.draw()

def motion_notify_callback(self, event):
'on mouse movement'
if not self.showverts: return
if self._ind is None: return
if event.inaxes is None: return
if event.button != 1: return
if not self.showverts:
return
if self._ind is None:
return
if event.inaxes is None:
return
if event.button != 1:
return
x, y = event.xdata, event.ydata

vertices = self.pathpatch.get_path().vertices
Expand Down
5 changes: 3 additions & 2 deletions examples/event_handling/pick_event_demo.py
Expand Up @@ -116,11 +116,12 @@ def line_picker(line, mouseevent):
data coords and attach some extra attributes, pickx and picky
which are the data points that were picked
"""
if mouseevent.xdata is None: return False, dict()
if mouseevent.xdata is None:
return False, dict()
xdata = line.get_xdata()
ydata = line.get_ydata()
maxd = 0.05
d = np.sqrt((xdata-mouseevent.xdata)**2. + (ydata-mouseevent.ydata)**2.)
d = np.sqrt((xdata - mouseevent.xdata)**2. + (ydata - mouseevent.ydata)**2.)

ind = np.nonzero(np.less_equal(d, maxd))
if len(ind):
Expand Down
8 changes: 5 additions & 3 deletions examples/event_handling/pick_event_demo2.py
Expand Up @@ -18,14 +18,16 @@

def onpick(event):

if event.artist != line: return True
if event.artist != line:
return True

N = len(event.ind)
if not N: return True
if not N:
return True

figi = plt.figure()
for subplotnum, dataind in enumerate(event.ind):
ax = figi.add_subplot(N, 1, subplotnum+1)
ax = figi.add_subplot(N, 1, subplotnum + 1)
ax.plot(X[dataind])
ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
transform=ax.transAxes, va='top')
Expand Down
35 changes: 18 additions & 17 deletions examples/event_handling/pipong.py
Expand Up @@ -79,18 +79,19 @@ def update(self, pads):
self.vx *= 1.2 * pad.signx
self.vy *= 1.2 * pad.signy
fudge = .001
# probably cleaner with something like...if not self.field.contains(self.x, self.y):
if self.x < 0+fudge:
# probably cleaner with something like...
#if not self.field.contains(self.x, self.y):
if self.x < fudge:
#print("player A loses")
pads[1].score += 1;
pads[1].score += 1
self._reset(pads[0])
return True
if self.x > 7-fudge:
if self.x > 7 - fudge:
#print("player B loses")
pads[0].score += 1;
pads[0].score += 1
self._reset(pads[1])
return True
if self.y < -1+fudge or self.y > 1-fudge:
if self.y < -1 + fudge or self.y > 1 - fudge:
self.vy *= -1.0
# add some randomness, just to make it interesting
self.vy -= (randn()/300.0 + 1/300.0) * np.sign(self.vy)
Expand Down Expand Up @@ -149,11 +150,11 @@ def __init__(self, ax):
self.pads.append(Pad(pB, padBx, padBy, 'r'))
self.pucks = []
self.i = self.ax.annotate(instructions, (.5, 0.5),
name='monospace',
verticalalignment='center',
horizontalalignment='center',
multialignment='left',
textcoords='axes fraction', animated=True)
name='monospace',
verticalalignment='center',
horizontalalignment='center',
multialignment='left',
textcoords='axes fraction', animated=True)
self.canvas.mpl_connect('key_press_event', self.key_press)

def draw(self, evt):
Expand All @@ -166,10 +167,10 @@ def draw(self, evt):

# show the distractors
if self.distract:
self.line.set_ydata(np.sin(self.x+self.cnt/self.res))
self.line2.set_ydata(np.cos(self.x-self.cnt/self.res))
self.line3.set_ydata(np.tan(self.x+self.cnt/self.res))
self.line4.set_ydata(np.tan(self.x-self.cnt/self.res))
self.line.set_ydata(np.sin(self.x + self.cnt/self.res))
self.line2.set_ydata(np.cos(self.x - self.cnt/self.res))
self.line3.set_ydata(np.tan(self.x + self.cnt/self.res))
self.line4.set_ydata(np.tan(self.x - self.cnt/self.res))
draw_artist(self.line)
draw_artist(self.line2)
draw_artist(self.line3)
Expand Down Expand Up @@ -224,7 +225,7 @@ def key_press(self, event):
if event.key == 'e':
self.pads[0].y += .1
if self.pads[0].y > 1 - .3:
self.pads[0].y = 1-.3
self.pads[0].y = 1 - .3
if event.key == 'd':
self.pads[0].y -= .1
if self.pads[0].y < -1:
Expand All @@ -233,7 +234,7 @@ def key_press(self, event):
if event.key == 'i':
self.pads[1].y += .1
if self.pads[1].y > 1 - .3:
self.pads[1].y = 1-.3
self.pads[1].y = 1 - .3
if event.key == 'k':
self.pads[1].y -= .1
if self.pads[1].y < -1:
Expand Down

0 comments on commit ebde05f

Please sign in to comment.