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

Skip to content

Commit ff2cdf5

Browse files
committed
added radio buttons
svn path=/trunk/matplotlib/; revision=1452
1 parent f048d93 commit ff2cdf5

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

examples/widgets/radio_buttons.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@
99
l, = ax.plot(t, s0, lw=2, color='red')
1010
subplots_adjust(left=0.3)
1111

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)
1520

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)
2627

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)
2932
draw()
30-
radio.on_clicked(func)
33+
radio.on_clicked(stylefunc)
3134

3235
show()

lib/matplotlib/widgets.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
"""
22
GUI Neutral widgets
3+
4+
All of these widgets require you to predefine an Axes instance and
5+
pass that as the first arg. matplotlib doesn't try to be too smart in
6+
layout -- you have to figure out how wide and tall you want your Axes
7+
to be to accommodate your widget.
38
"""
49

510
from matplotlib.mlab import linspace, dist

0 commit comments

Comments
 (0)