本稿ではJuliaによるmatplotlibを使ったインタラクティブプロット(Radio Button編)について紹介します.
基本的には本家サイトにあるmatplotlib.widgetsのサンプルソースの移植版です.
radio_buttons.jl
#Translated from python to julia (reffer to https://matplotlib.org/examples/widgets/radio_buttons.html)
#Julia v0.6.2
#PyCall v3.6.4
using PyCall
using PyPlot
const RadioButtons = matplotlib[:widgets][:RadioButtons]
t = 0.0:0.01:2.0
s0 = sin.(2*π*t)
s1 = sin.(4*π*t)
s2 = sin.(8*π*t)
fig, ax = subplots()
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], facecolor=axcolor)
radio = RadioButtons(rax, ("2 Hz", "4 Hz", "8 Hz"))
function hzfunc(label)
hzdict = Dict("2 Hz"=> s0, "4 Hz"=> s1, "8 Hz"=> s2)
ydata = hzdict[label]
l[:set_ydata](ydata)
draw()
end
radio[:on_clicked](hzfunc)
rax = axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor)
radio2 = RadioButtons(rax, ("red", "blue", "green"))
function colorfunc(label)
l[:set_color](label)
draw()
end
radio2[:on_clicked](colorfunc)
rax =axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor)
radio3 = RadioButtons(rax, ("-", "--", "-.", "steps", ":"))
function stylefunc(label)
l[:set_linestyle](label)
draw()
end
radio3[:on_clicked](stylefunc)
show()