1
1

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でインタラクティブプロット(Button編)

Posted at

本稿ではJuliaによるmatplotlibを使ったインタラクティブプロット(Button編)について紹介します.
基本的には本家サイトにあるmatplotlib.widgetsのサンプルソースの移植版です.

buttons.jl
#Translated from python to julia (reffer to https://matplotlib.org/examples/widgets/buttons.html)
#Julia v0.6.2
#PyCall v3.6.4

using PyCall
using PyPlot

const Button = matplotlib[:widgets][:Button]

freqs = 2:3:20

fig, ax = subplots()
subplots_adjust(bottom=0.2)
t = 0.0:0.001:1.0
s = sin.(2*π*freqs[1]*t)
l, = plot(t, s, lw=2)
ind = 1

function next_(event)
    eval(:(ind += 1))
    i = (ind % length(freqs)) + 1
    ydata = sin.(2*π*freqs[i]*t)
    l[:set_ydata](ydata)
    draw()
end

function prev_(event)
    ind > 0 ? eval(:(ind -= 1)) : eval(:(ind=length(freqs)))
    i = (ind % length(freqs)) + 1
    ydata = sin.(2*π*freqs[i]*t)
    l[:set_ydata](ydata)
    draw()
end

axprev = axes([0.7, 0.05, 0.1, 0.075])
axnext = axes([0.81, 0.05, 0.1, 0.075])
bnext = Button(axnext, "Next")
bnext[:on_clicked](next_)
bprev = Button(axprev, "Previous")
bprev[:on_clicked](prev_)

show()

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

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?