Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Access the recorded webinar.

Animation using Julia and Plotly in Jupyter Notebook

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