Menu

[r4674]: / trunk / htdocs / examples / widgets / radio_buttons.py  Maximize  Restore  History

Download this file

37 lines (31 with data), 912 Bytes

 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
from matplotlib.widgets import RadioButtons
from pylab import *
t = arange(0.0, 2.0, 0.01)
s0 = sin(2*pi*t)
s1 = sin(4*pi*t)
s2 = sin(8*pi*t)
ax = subplot(111)
l, = ax.plot(t, s0, lw=2, color='red')
subplots_adjust(left=0.3)
axcolor = 'lightgoldenrodyellow'
rax = axes([0.05, 0.7, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz'))
def hzfunc(label):
hzdict = {'2 Hz':s0, '4 Hz':s1, '8 Hz':s2}
ydata = hzdict[label]
l.set_ydata(ydata)
draw()
radio.on_clicked(hzfunc)
rax = axes([0.05, 0.4, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'))
def colorfunc(label):
l.set_color(label)
draw()
radio.on_clicked(colorfunc)
rax = axes([0.05, 0.1, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('-', '--', '-.', 'steps', ':'))
def stylefunc(label):
l.set_linestyle(label)
draw()
radio.on_clicked(stylefunc)
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.