1"""
2=============
3Radio Buttons
4=============
5
6Using radio buttons to choose properties of your plot.
7
8Radio buttons let you choose between multiple options in a visualization.
9In this case, the buttons let the user choose one of the three different sine
10waves to be shown in the plot.
11"""
12import numpy as np
13import matplotlib.pyplot as plt
14from matplotlib.widgets import RadioButtons
15
16t = np.arange(0.0, 2.0, 0.01)
17s0 = np.sin(2*np.pi*t)
18s1 = np.sin(4*np.pi*t)
19s2 = np.sin(8*np.pi*t)
20
21fig, ax = plt.subplots()
22l, = ax.plot(t, s0, lw=2, color='red')
23plt.subplots_adjust(left=0.3)
24
25axcolor = 'lightgoldenrodyellow'
26rax = plt.axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor)
27radio = RadioButtons(rax, ('2 Hz', '4 Hz', '8 Hz'))
28
29
30def hzfunc(label):
31    hzdict = {'2 Hz': s0, '4 Hz': s1, '8 Hz': s2}
32    ydata = hzdict[label]
33    l.set_ydata(ydata)
34    plt.draw()
35radio.on_clicked(hzfunc)
36
37rax = plt.axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor)
38radio2 = RadioButtons(rax, ('red', 'blue', 'green'))
39
40
41def colorfunc(label):
42    l.set_color(label)
43    plt.draw()
44radio2.on_clicked(colorfunc)
45
46rax = plt.axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor)
47radio3 = RadioButtons(rax, ('-', '--', '-.', 'steps', ':'))
48
49
50def stylefunc(label):
51    l.set_linestyle(label)
52    plt.draw()
53radio3.on_clicked(stylefunc)
54
55plt.show()
56
57#############################################################################
58#
59# .. admonition:: References
60#
61#    The use of the following functions, methods, classes and modules is shown
62#    in this example:
63#
64#    - `matplotlib.widgets.RadioButtons`
65