|
9 | 9 | l, = ax.plot(t, s0, lw=2, color='red') |
10 | 10 | subplots_adjust(left=0.3) |
11 | 11 |
|
12 | | -rax = axes([0.05, 0.4, 0.175, 0.175]) |
13 | | -radio = RadioButtons(rax, ('button 1', 'button 2', 'button 3')) |
14 | | - |
| 12 | +rax = axes([0.05, 0.7, 0.175, 0.175]) |
| 13 | +radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz')) |
| 14 | +def hzfunc(label): |
| 15 | + hzdict = {'2 Hz':s0, '4 Hz':s1, '8 Hz':s2} |
| 16 | + ydata = hzdict[label] |
| 17 | + l.set_ydata(ydata) |
| 18 | + draw() |
| 19 | +radio.on_clicked(hzfunc) |
15 | 20 |
|
16 | | -def func(label): |
17 | | - if label=='button 1': |
18 | | - ydata = s0 |
19 | | - color = 'red' |
20 | | - elif label=='button 2': |
21 | | - ydata = s1 |
22 | | - color='blue' |
23 | | - elif label=='button 3': |
24 | | - ydata = s2 |
25 | | - color='green' |
| 21 | +rax = axes([0.05, 0.4, 0.175, 0.175]) |
| 22 | +radio = RadioButtons(rax, ('red', 'blue', 'green')) |
| 23 | +def colorfunc(label): |
| 24 | + l.set_color(label) |
| 25 | + draw() |
| 26 | +radio.on_clicked(colorfunc) |
26 | 27 |
|
27 | | - l.set_ydata(ydata) |
28 | | - l.set_color(color) |
| 28 | +rax = axes([0.05, 0.1, 0.175, 0.175]) |
| 29 | +radio = RadioButtons(rax, ('-', '--', '-.', 'steps', ':')) |
| 30 | +def stylefunc(label): |
| 31 | + l.set_linestyle(label) |
29 | 32 | draw() |
30 | | -radio.on_clicked(func) |
| 33 | +radio.on_clicked(stylefunc) |
31 | 34 |
|
32 | 35 | show() |
0 commit comments