Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b072e05

Browse filesBrowse files
committed
pep8ify examples (part2)
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
1 parent 7b4a3a9 commit b072e05
Copy full SHA for b072e05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

68 files changed

+614
-523
lines changed

‎examples/color/color_cycle_demo.py

Copy file name to clipboardExpand all lines: examples/color/color_cycle_demo.py
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
yy = np.transpose([np.sin(x + phi) for phi in offsets])
1818

1919
plt.rc('lines', linewidth=4)
20-
fig, (ax0, ax1) = plt.subplots(nrows=2)
20+
fig, (ax0, ax1) = plt.subplots(nrows=2)
2121

2222
plt.rc('axes', color_cycle=['r', 'g', 'b', 'y'])
2323
ax0.plot(yy)
@@ -30,5 +30,3 @@
3030
# Tweak spacing between subplots to prevent labels from overlapping
3131
plt.subplots_adjust(hspace=0.3)
3232
plt.show()
33-
34-

‎examples/color/colormaps_reference.py

Copy file name to clipboardExpand all lines: examples/color/colormaps_reference.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
gradient = np.linspace(0, 1, 256)
6060
gradient = np.vstack((gradient, gradient))
6161

62+
6263
def plot_color_gradients(cmap_category, cmap_list):
6364
fig, axes = plt.subplots(nrows=nrows)
6465
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)

‎examples/event_handling/close_event.py

Copy file name to clipboardExpand all lines: examples/event_handling/close_event.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22
import matplotlib.pyplot as plt
33

4+
45
def handle_close(evt):
56
print('Closed Figure!')
67

‎examples/event_handling/data_browser.py

Copy file name to clipboardExpand all lines: examples/event_handling/data_browser.py
+28-23Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class PointBrowser:
77
generated the point will be shown in the lower axes. Use the 'n'
88
and 'p' keys to browse through the next and previous points
99
"""
10+
1011
def __init__(self):
1112
self.lastind = 0
1213

@@ -16,50 +17,55 @@ def __init__(self):
1617
color='yellow', visible=False)
1718

1819
def onpress(self, event):
19-
if self.lastind is None: return
20-
if event.key not in ('n', 'p'): return
21-
if event.key=='n': inc = 1
22-
else: inc = -1
23-
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
32-
33-
N = len(event.ind)
34-
if not N: return True
35+
if event.artist != line:
36+
return True
3537

36-
# the click locations
37-
x = event.mouseevent.xdata
38-
y = event.mouseevent.ydata
38+
N = len(event.ind)
39+
if not N:
40+
return True
3941

42+
# the click locations
43+
x = event.mouseevent.xdata
44+
y = event.mouseevent.ydata
4045

41-
distances = np.hypot(x-xs[event.ind], y-ys[event.ind])
42-
indmin = distances.argmin()
43-
dataind = event.ind[indmin]
46+
distances = np.hypot(x - xs[event.ind], y - ys[event.ind])
47+
indmin = distances.argmin()
48+
dataind = event.ind[indmin]
4449

45-
self.lastind = dataind
46-
self.update()
50+
self.lastind = dataind
51+
self.update()
4752

4853
def update(self):
49-
if self.lastind is None: return
54+
if self.lastind is None:
55+
return
5056

5157
dataind = self.lastind
5258

5359
ax2.cla()
5460
ax2.plot(X[dataind])
5561

56-
ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]),
57-
transform=ax2.transAxes, va='top')
62+
ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (
63+
xs[dataind], ys[dataind]), transform=ax2.transAxes, va='top')
5864
ax2.set_ylim(-0.5, 1.5)
5965
self.selected.set_visible(True)
6066
self.selected.set_data(xs[dataind], ys[dataind])
6167

62-
self.text.set_text('selected: %d'%dataind)
68+
self.text.set_text('selected: %d' % dataind)
6369
fig.canvas.draw()
6470

6571

@@ -80,4 +86,3 @@ def update(self):
8086
fig.canvas.mpl_connect('key_press_event', browser.onpress)
8187

8288
plt.show()
83-

‎examples/event_handling/figure_axes_enter_leave.py

Copy file name to clipboardExpand all lines: examples/event_handling/figure_axes_enter_leave.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
from __future__ import print_function
66
import matplotlib.pyplot as plt
77

8+
89
def enter_axes(event):
910
print('enter_axes', event.inaxes)
1011
event.inaxes.patch.set_facecolor('yellow')
1112
event.canvas.draw()
1213

14+
1315
def leave_axes(event):
1416
print('leave_axes', event.inaxes)
1517
event.inaxes.patch.set_facecolor('white')
1618
event.canvas.draw()
1719

20+
1821
def enter_figure(event):
1922
print('enter_figure', event.canvas.figure)
2023
event.canvas.figure.patch.set_facecolor('red')
2124
event.canvas.draw()
2225

26+
2327
def leave_figure(event):
2428
print('leave_figure', event.canvas.figure)
2529
event.canvas.figure.patch.set_facecolor('grey')
@@ -42,5 +46,3 @@ def leave_figure(event):
4246
fig2.canvas.mpl_connect('axes_leave_event', leave_axes)
4347

4448
plt.show()
45-
46-

‎examples/event_handling/idle_and_timeout.py

Copy file name to clipboardExpand all lines: examples/event_handling/idle_and_timeout.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
line2, = ax.plot(y2)
1717

1818
N = 100
19+
20+
1921
def on_idle(event):
20-
on_idle.count +=1
22+
on_idle.count += 1
2123
print('idle', on_idle.count)
22-
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)))
2325
event.canvas.draw()
2426
# test boolean return removal
25-
if on_idle.count==N:
27+
if on_idle.count == N:
2628
return False
2729
return True
2830
on_idle.cid = None
@@ -31,5 +33,3 @@ def on_idle(event):
3133
fig.canvas.mpl_connect('idle_event', on_idle)
3234

3335
plt.show()
34-
35-

‎examples/event_handling/keypress_demo.py

Copy file name to clipboardExpand all lines: examples/event_handling/keypress_demo.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def press(event):
1313
print('press', event.key)
1414
sys.stdout.flush()
15-
if event.key=='x':
15+
if event.key == 'x':
1616
visible = xl.get_visible()
1717
xl.set_visible(not visible)
1818
fig.canvas.draw()

‎examples/event_handling/lasso_demo.py

Copy file name to clipboardExpand all lines: examples/event_handling/lasso_demo.py
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
from numpy import nonzero
1616
from numpy.random import rand
1717

18+
1819
class Datum(object):
1920
colorin = colorConverter.to_rgba('red')
2021
colorout = colorConverter.to_rgba('blue')
22+
2123
def __init__(self, x, y, include=False):
2224
self.x = x
2325
self.y = y
24-
if include: self.color = self.colorin
25-
else: self.color = self.colorout
26+
if include:
27+
self.color = self.colorin
28+
else:
29+
self.color = self.colorout
2630

2731

2832
class LassoManager(object):
@@ -61,17 +65,20 @@ def callback(self, verts):
6165
del self.lasso
6266

6367
def onpress(self, event):
64-
if self.canvas.widgetlock.locked(): return
65-
if event.inaxes is None: return
66-
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
68+
if self.canvas.widgetlock.locked():
69+
return
70+
if event.inaxes is None:
71+
return
72+
self.lasso = Lasso(
73+
event.inaxes, (event.xdata, event.ydata), self.callback)
6774
# acquire a lock on the widget drawing
6875
self.canvas.widgetlock(self.lasso)
6976

7077
if __name__ == '__main__':
7178

7279
data = [Datum(*xy) for xy in rand(100, 2)]
7380

74-
ax = plt.axes(xlim=(0,1), ylim=(0,1), autoscale_on=False)
81+
ax = plt.axes(xlim=(0, 1), ylim=(0, 1), autoscale_on=False)
7582
lman = LassoManager(ax, data)
7683

7784
plt.show()

‎examples/event_handling/looking_glass.py

Copy file name to clipboardExpand all lines: examples/event_handling/looking_glass.py
+31-30Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,44 @@
44
x, y = np.random.rand(2, 200)
55

66
fig, ax = plt.subplots()
7-
circ = patches.Circle( (0.5, 0.5), 0.25, alpha=0.8, fc='yellow')
7+
circ = patches.Circle((0.5, 0.5), 0.25, alpha=0.8, fc='yellow')
88
ax.add_patch(circ)
99

1010

1111
ax.plot(x, y, alpha=0.2)
1212
line, = ax.plot(x, y, alpha=1.0, clip_path=circ)
1313

14+
1415
class EventHandler:
15-
def __init__(self):
16-
fig.canvas.mpl_connect('button_press_event', self.onpress)
17-
fig.canvas.mpl_connect('button_release_event', self.onrelease)
18-
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
19-
self.x0, self.y0 = circ.center
20-
self.pressevent = None
21-
22-
def onpress(self, event):
23-
if event.inaxes!=ax:
24-
return
25-
26-
if not circ.contains(event)[0]:
27-
return
28-
29-
self.pressevent = event
30-
31-
def onrelease(self, event):
32-
self.pressevent = None
33-
self.x0, self.y0 = circ.center
34-
35-
def onmove(self, event):
36-
if self.pressevent is None or event.inaxes!=self.pressevent.inaxes:
37-
return
38-
39-
dx = event.xdata - self.pressevent.xdata
40-
dy = event.ydata - self.pressevent.ydata
41-
circ.center = self.x0 + dx, self.y0 + dy
42-
line.set_clip_path(circ)
43-
fig.canvas.draw()
16+
def __init__(self):
17+
fig.canvas.mpl_connect('button_press_event', self.onpress)
18+
fig.canvas.mpl_connect('button_release_event', self.onrelease)
19+
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
20+
self.x0, self.y0 = circ.center
21+
self.pressevent = None
22+
23+
def onpress(self, event):
24+
if event.inaxes != ax:
25+
return
26+
27+
if not circ.contains(event)[0]:
28+
return
29+
30+
self.pressevent = event
31+
32+
def onrelease(self, event):
33+
self.pressevent = None
34+
self.x0, self.y0 = circ.center
35+
36+
def onmove(self, event):
37+
if self.pressevent is None or event.inaxes != self.pressevent.inaxes:
38+
return
39+
40+
dx = event.xdata - self.pressevent.xdata
41+
dy = event.ydata - self.pressevent.ydata
42+
circ.center = self.x0 + dx, self.y0 + dy
43+
line.set_clip_path(circ)
44+
fig.canvas.draw()
4445

4546
handler = EventHandler()
4647
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.