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

Skip to content

Commit a549ab0

Browse files
committed
added buttons demo
svn path=/trunk/matplotlib/; revision=1453
1 parent ff2cdf5 commit a549ab0

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

examples/widgets/buttons.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pylab import *
2+
from matplotlib.widgets import Button
3+
4+
freqs = arange(2,20,3)
5+
6+
ax = subplot(111)
7+
subplots_adjust(bottom=0.2)
8+
t = arange(0.0, 1.0, 0.001)
9+
s = sin(2*pi*freqs[0]*t)
10+
l, = plot(t,s, lw=2)
11+
12+
13+
class Index:
14+
ind = 0
15+
def next(self, event):
16+
self.ind += 1
17+
i = self.ind%len(freqs)
18+
ydata = sin(2*pi*freqs[i]*t)
19+
l.set_ydata(ydata)
20+
draw()
21+
22+
def prev(self, event):
23+
self.ind -= 1
24+
i = self.ind%len(freqs)
25+
ydata = sin(2*pi*freqs[i]*t)
26+
l.set_ydata(ydata)
27+
draw()
28+
29+
callback = Index()
30+
axprev = axes([0.7, 0.05, 0.1, 0.075])
31+
axnext = axes([0.81, 0.05, 0.1, 0.075])
32+
bnext = Button(axnext, 'Next')
33+
bnext.on_clicked(callback.next)
34+
bprev = Button(axprev, 'Previous')
35+
bprev.on_clicked(callback.prev)
36+
37+
show()
38+

0 commit comments

Comments
 (0)