Julia animation using PlotlyJS

Hi, I am happy to share some code that shows how to do animations using Julia and PlotlyJS on a Jupyter Notebook.

JuliaPlotlyAnim

On the first cell of a Jupyter Notebook insert

using PlotlyJS

t = LinRange(0.0,2*pi,250)
ω1 = 2
ω2 = 3
a0 = 0
trace = scatter(x=cos.(ω1*t),y=sin.(ω2*a0*t),mode="lines", name="Lissajous") 
data = [trace]
layout = Layout(;title="Animation", xaxis_range=[-2, 2],
                     yaxis_range=[-2, 2], width=500,height=500)
pl = plot(data,layout)

On the next cell

a1 = 1
for a in LinRange(a0,a1,100)
    trace = scatter(x=cos.(ω1*t),y=sin.(ω2*a*t),mode="lines", name="Lissajous") 
    data = [trace]
    sleep(0.05)
    react!(pl, data, layout)
end
10 Likes