0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Juliaでインタラクティブプロット(Radio Button編)

Posted at

本稿では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()

スクリーンショット 2018-05-10 22.34.19.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?