Skip to content

[examples] fix pep8 error classes e225, e227 and e228 #3771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/event_handling/data_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
def onpress(self, event):
if self.lastind is None: return
if event.key not in ('n', 'p'): return
if event.key=='n': inc = 1
if event.key == 'n': inc = 1
else: inc = -1

self.lastind += inc
Expand All @@ -28,7 +28,7 @@ def onpress(self, event):

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
Expand All @@ -52,13 +52,13 @@ def update(self):
ax2.cla()
ax2.plot(X[dataind])

ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]),
ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
transform=ax2.transAxes, va='top')
ax2.set_ylim(-0.5, 1.5)
self.selected.set_visible(True)
self.selected.set_data(xs[dataind], ys[dataind])

self.text.set_text('selected: %d'%dataind)
self.text.set_text('selected: %d' % dataind)
fig.canvas.draw()


Expand Down
4 changes: 2 additions & 2 deletions examples/event_handling/idle_and_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@


def on_idle(event):
on_idle.count +=1
on_idle.count += 1
print('idle', on_idle.count)
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:
if on_idle.count == N:
return False
return True
on_idle.cid = None
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handling/keypress_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def press(event):
print('press', event.key)
sys.stdout.flush()
if event.key=='x':
if event.key == 'x':
visible = xl.get_visible()
xl.set_visible(not visible)
fig.canvas.draw()
Expand Down
4 changes: 2 additions & 2 deletions examples/event_handling/looking_glass.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self):
self.pressevent = None

def onpress(self, event):
if event.inaxes!=ax:
if event.inaxes != ax:
return

if not circ.contains(event)[0]:
Expand All @@ -34,7 +34,7 @@ def onrelease(self, event):
self.x0, self.y0 = circ.center

def onmove(self, event):
if self.pressevent is None or event.inaxes!=self.pressevent.inaxes:
if self.pressevent is None or event.inaxes != self.pressevent.inaxes:
return

dx = event.xdata - self.pressevent.xdata
Expand Down
6 changes: 3 additions & 3 deletions examples/event_handling/path_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ def get_ind_under_point(self, event):
d = np.sqrt((xt-event.x)**2 + (yt-event.y)**2)
ind = d.argmin()

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

return ind

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

Expand All @@ -104,7 +104,7 @@ def button_release_callback(self, event):
def key_press_callback(self, event):
'whenever a key is pressed'
if not event.inaxes: return
if event.key=='t':
if event.key == 't':
self.showverts = not self.showverts
self.line.set_visible(self.showverts)
if not self.showverts: self._ind = None
Expand Down
4 changes: 2 additions & 2 deletions examples/event_handling/pick_event_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def onpick(event):

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

N = len(event.ind)
if not N: return True
Expand All @@ -27,7 +27,7 @@ def onpick(event):
for subplotnum, dataind in enumerate(event.ind):
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]),
ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
transform=ax.transAxes, va='top')
ax.set_ylim(-0.5, 1.5)
figi.show()
Expand Down
24 changes: 12 additions & 12 deletions examples/event_handling/pipong.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def __init__(self, disp, x, y, type='l'):
self.score = 0
self.xoffset = 0.3
self.yoffset = 0.1
if type=='r':
if type == 'r':
self.xoffset *= -1.0

if type=='l' or type=='r':
if type == 'l' or type == 'r':
self.signx = -1.0
self.signy = 1.0
else:
Expand All @@ -54,7 +54,7 @@ def contains(self, loc):

class Puck(object):
def __init__(self, disp, pad, field):
self.vmax= .2
self.vmax = .2
self.disp = disp
self.field = field
self._reset(pad)
Expand All @@ -76,8 +76,8 @@ def update(self, pads):
self.y += self.vy
for pad in pads:
if pad.contains(self):
self.vx *= 1.2 *pad.signx
self.vy *= 1.2 *pad.signy
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:
Expand Down Expand Up @@ -121,9 +121,9 @@ class Game(object):
def __init__(self, ax):
# create the initial line
self.ax = ax
padAx = padBx= .50
padAy = padBy= .30
padBx+=6.3
padAx = padBx = .50
padAy = padBy = .30
padBx += 6.3
pA, = self.ax.barh(padAy, .2, height=.3, color='k', alpha=.5, edgecolor='b', lw=2, label="Player B", animated=True)
pB, = self.ax.barh(padBy, .2, height=.3, left=padBx, color='k', alpha=.5, edgecolor='r', lw=2, label="Player A", animated=True)

Expand All @@ -147,7 +147,7 @@ def __init__(self, ax):
self.pads = []
self.pads.append(Pad(pA, 0, padAy))
self.pads.append(Pad(pB, padBx, padBy, 'r'))
self.pucks =[]
self.pucks = []
self.i = self.ax.annotate(instructions, (.5, 0.5),
name='monospace',
verticalalignment='center',
Expand Down Expand Up @@ -190,8 +190,8 @@ def draw(self, evt):
for puck in self.pucks:
if puck.update(self.pads):
# we only get here if someone scored
self.pads[0].disp.set_label(" "+ str(self.pads[0].score))
self.pads[1].disp.set_label(" "+ str(self.pads[1].score))
self.pads[0].disp.set_label(" " + str(self.pads[0].score))
self.pads[1].disp.set_label(" " + str(self.pads[1].score))
self.ax.legend(loc='center')
self.leg = self.ax.get_legend()
#self.leg.draw_frame(False) #don't draw the legend border
Expand All @@ -207,7 +207,7 @@ def draw(self, evt):
# just redraw the axes rectangle
self.canvas.blit(self.ax.bbox)

if self.cnt==50000:
if self.cnt == 50000:
# just so we don't get carried away
print("...and you've been playing for too long!!!")
plt.close()
Expand Down
14 changes: 7 additions & 7 deletions examples/event_handling/poly_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def get_ind_under_point(self, event):
indseq = np.nonzero(np.equal(d, np.amin(d)))[0]
ind = indseq[0]

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

return ind

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

Expand All @@ -95,23 +95,23 @@ def button_release_callback(self, event):
def key_press_callback(self, event):
'whenever a key is pressed'
if not event.inaxes: return
if event.key=='t':
if event.key == 't':
self.showverts = not self.showverts
self.line.set_visible(self.showverts)
if not self.showverts: self._ind = None
elif event.key=='d':
elif event.key == 'd':
ind = self.get_ind_under_point(event)
if ind is not None:
self.poly.xy = [tup for i, tup in enumerate(self.poly.xy) if i!=ind]
self.poly.xy = [tup for i, tup in enumerate(self.poly.xy) if i != ind]
self.line.set_data(zip(*self.poly.xy))
elif event.key=='i':
elif event.key == 'i':
xys = self.poly.get_transform().transform(self.poly.xy)
p = event.x, event.y # display coords
for i in range(len(xys)-1):
s0 = xys[i]
s1 = xys[i+1]
d = dist_point_to_segment(p, s0, s1)
if d<=self.epsilon:
if d <= self.epsilon:
self.poly.xy = np.array(
list(self.poly.xy[:i]) +
[(event.xdata, event.ydata)] +
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handling/zoom_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def onpress(event):
if event.button!=1: return
if event.button != 1: return
x, y = event.xdata, event.ydata
axzoom.set_xlim(x-0.1, x+0.1)
axzoom.set_ylim(y-0.1, y+0.1)
Expand Down
8 changes: 4 additions & 4 deletions examples/misc/image_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import matplotlib.image as image


if len(sys.argv)!=2:
print('Usage: python %s IMAGEDIR'%__file__)
if len(sys.argv) != 2:
print('Usage: python %s IMAGEDIR' % __file__)
raise SystemExit
indir = sys.argv[1]
if not os.path.isdir(indir):
print('Could not find input directory "%s"'%indir)
print('Could not find input directory "%s"' % indir)
raise SystemExit

outdir = 'thumbs'
Expand All @@ -26,4 +26,4 @@
basedir, basename = os.path.split(fname)
outfile = os.path.join(outdir, basename)
fig = image.thumbnail(fname, outfile, scale=0.15)
print('saved thumbnail of %s to %s'%(fname, outfile))
print('saved thumbnail of %s to %s' % (fname, outfile))
6 changes: 3 additions & 3 deletions examples/misc/rc_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ def __init__(self, r=0., g=0., b=0., a=1.):
self.a = a

def __repr__(self):
return 'r,g,b,a = (%1.2f, %1.2f, %1.2f, %1.2f)'%\
return 'r,g,b,a = (%1.2f, %1.2f, %1.2f, %1.2f)' %\
(self.r, self.g, self.b, self.a)


def tuple_to_rgba(ob, name, val):
tup = [float(x) for x in val]
if len(tup)==3:
if len(tup) == 3:
r, g, b = tup
return RGBA(r, g, b)
elif len(tup)==4:
elif len(tup) == 4:
r, g, b, a = tup
return RGBA(r, g, b, a)
else:
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/svg_filter_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]

explode=(0, 0.05, 0, 0)
explode = (0, 0.05, 0, 0)

# We want to draw the shadow for each pie but we will not use "shadow"
# option as it does'n save the references to the shadow patches.
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/animation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
z = x * y[:, np.newaxis]

for i in xrange(5):
if i==0:
if i == 0:
p = plt.imshow(z)
fig = plt.gcf()
plt.clim() # clamp the color limits
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/anscombe.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def fit(x):
# verify the stats
pairs = (x, y1), (x, y2), (x, y3), (x4, y4)
for x, y in pairs:
print('mean=%1.2f, std=%1.2f, r=%1.2f'%(mean(y), std(y), corrcoef(x, y)[0][1]))
print('mean=%1.2f, std=%1.2f, r=%1.2f' % (mean(y), std(y), corrcoef(x, y)[0][1]))

show()
12 changes: 6 additions & 6 deletions examples/pylab_examples/arrow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
from pylab import *

rates_to_bases={'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA', 'r6': 'AC', \
rates_to_bases = {'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA', 'r6': 'AC', \
'r7': 'GT', 'r8': 'TG', 'r9': 'CT', 'r10': 'TC', 'r11': 'GC', 'r12': 'CG'}
numbered_bases_to_rates = dict([(v, k) for k, v in rates_to_bases.items()])
lettered_bases_to_rates = dict([(v, 'r'+v) for k, v in rates_to_bases.items()])
Expand Down Expand Up @@ -53,7 +53,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', \
max_text_size = size*12
min_text_size = size
label_text_size = size*2.5
text_params={'ha': 'center', 'va': 'center', 'family': 'sans-serif',\
text_params = {'ha': 'center', 'va': 'center', 'family': 'sans-serif',\
'fontweight': 'bold'}
r2 = sqrt(2)

Expand Down Expand Up @@ -117,7 +117,7 @@ def do_fontsize(k):
max_arrow_width = max_arrow_width
max_head_width = 2.5*max_arrow_width
max_head_length = 2*max_arrow_width
arrow_params={'length_includes_head': True, 'shape': shape, \
arrow_params = {'length_includes_head': True, 'shape': shape, \
'head_starts_at_zero': head_starts_at_zero}
ax = gca()
sf = 0.6 # max arrow size represents this in data coords
Expand Down Expand Up @@ -154,15 +154,15 @@ def do_fontsize(k):
def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
# set the length of the arrow
if display == 'length':
length = max_head_length+(max_arrow_length-max_head_length)*\
length = max_head_length+(max_arrow_length-max_head_length) *\
data[pair]/sf
else:
length = max_arrow_length
# set the transparency of the arrow
if display == 'alph':
alpha = min(data[pair]/sf, alpha)
else:
alpha=alpha
alpha = alpha
# set the width of the arrow
if display == 'width':
scale = data[pair]/sf
Expand Down Expand Up @@ -295,7 +295,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
scaled = True
if d is None:
d = all_on_max
scaled=False
scaled = False
if len(argv) > 2:
display = argv[2]
else:
Expand Down
12 changes: 6 additions & 6 deletions examples/pylab_examples/axes_zoom_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def zoom_effect01(ax1, ax2, xmin, xmax, **kwargs):
mybbox1 = TransformedBbox(bbox, trans1)
mybbox2 = TransformedBbox(bbox, trans2)

prop_patches=kwargs.copy()
prop_patches["ec"]="none"
prop_patches["alpha"]=0.2
prop_patches = kwargs.copy()
prop_patches["ec"] = "none"
prop_patches["alpha"] = 0.2

c1, c2, bbox_patch1, bbox_patch2, p = \
connect_bbox(mybbox1, mybbox2,
Expand Down Expand Up @@ -82,9 +82,9 @@ def zoom_effect02(ax1, ax2, **kwargs):
mybbox1 = ax1.bbox
mybbox2 = TransformedBbox(ax1.viewLim, trans)

prop_patches=kwargs.copy()
prop_patches["ec"]="none"
prop_patches["alpha"]=0.2
prop_patches = kwargs.copy()
prop_patches["ec"] = "none"
prop_patches["alpha"] = 0.2

c1, c2, bbox_patch1, bbox_patch2, p = \
connect_bbox(mybbox1, mybbox2,
Expand Down
Loading