File: buttons.py

package info (click to toggle)
matplotlib 0.99.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 33,060 kB
  • ctags: 28,162
  • sloc: python: 79,063; cpp: 64,496; objc: 4,513; ansic: 1,948; makefile: 146; sh: 7
file content (38 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from pylab import *
from matplotlib.widgets import Button

freqs = arange(2,20,3)

ax = subplot(111)
subplots_adjust(bottom=0.2)
t = arange(0.0, 1.0, 0.001)
s = sin(2*pi*freqs[0]*t)
l, = plot(t,s, lw=2)


class Index:
    ind = 0
    def next(self, event):
        self.ind += 1
        i = self.ind%len(freqs)
        ydata = sin(2*pi*freqs[i]*t)
        l.set_ydata(ydata)
        draw()

    def prev(self, event):
        self.ind -= 1
        i = self.ind%len(freqs)
        ydata = sin(2*pi*freqs[i]*t)
        l.set_ydata(ydata)
        draw()

callback = Index()
axprev = axes([0.7, 0.05, 0.1, 0.075])
axnext = axes([0.81, 0.05, 0.1, 0.075])
bnext = Button(axnext, 'Next')
bnext.on_clicked(callback.next)
bprev = Button(axprev, 'Previous')
bprev.on_clicked(callback.prev)

show()