# Animation using PlotlyBase

**URL:** <https://discourse.julialang.org/t/animation-using-plotlybase/63292>\
**Category:** General Usage\
**Tags:** plotting, plotlyjs, animations\
**Created:** [June 21, 2021, 12:28pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292 "2021-06-21T12:28:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oto\_Brzobohaty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oto_brzobohaty/32/10370_2.png) [@Oto\_Brzobohaty](https://discourse.julialang.org/u/Oto_Brzobohaty)\
**Post date:** [June 21, 2021, 12:28pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/1 "2021-06-21T12:28:35Z")

</div>

Dear PlotlyBase community, Is there a way how to get animation from [Animations · Plots](https://docs.juliaplots.org/latest/animations/) using pure PlotlyBase package?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 21, 2021, 4:22pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/2 "2021-06-21T16:22:09Z")

</div>

Have you checked [this PlotlyJS post?](https://discourse.julialang.org/t/animations-with-plotlyjs/34633/2)

---

<div class="post-metadata">

**Author:** ![Oto\_Brzobohaty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oto_brzobohaty/32/10370_2.png) [@Oto\_Brzobohaty](https://discourse.julialang.org/u/Oto_Brzobohaty)\
**Post date:** [June 21, 2021, 5:17pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/3 "2021-06-21T17:17:55Z")

</div>

Yes I am aware of this thread, but I am not able to find it there

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 21, 2021, 7:51pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/4 "2021-06-21T19:51:02Z")

</div>

@PetrKryslUCSD can confirm how he produced the nice animations. From his reply he seems to be using `react!` as in [code example here](https://github.com/PetrKryslUCSD/FinEtoolsFlexBeams.jl/blob/a1a843f850af58af1a1761852b659c17baa6807d/examples/graphics/loading_plot.jl).

_ **NB:** _  
_As a workaround to save animated GIFs, you may use some nice free open source SW such as **ShareX** in Windows, Flameshot in Linux, etc._

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [June 21, 2021, 8:05pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/5 "2021-06-21T20:05:52Z")

</div>

What exactly do you need? Do you want to use Plots, or would PlotlyJS work for you?

---

<div class="post-metadata">

**Author:** ![Oto\_Brzobohaty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oto_brzobohaty/32/10370_2.png) [@Oto\_Brzobohaty](https://discourse.julialang.org/u/Oto_Brzobohaty)\
**Post date:** [June 22, 2021, 5:32am UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/6 "2021-06-22T05:32:03Z")

</div>

I would like to use pure PlotlyJS to make animation (exported to gif) like this:

```julia
anim = @animate for i ∈ 1:n
    Plot_st_using_PlotlyJS
end
gif(anim, "anim_fps15.gif", fps = 15)

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [June 22, 2021, 5:41pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/7 "2021-06-22T17:41:25Z")

</div>

This works:

```julia
using PlotlyJS

layout = Layout(width = 500, height = 500)
layout[:title] = ""
layout[:showSendToCloud] = true
layout[:showLegend] = true
layout[:showEditInChartStudio] = true

f(frame) = if frame < 10; "0$frame"; else "$frame"; end

frame = 1
xyz = rand(frame, 3)
plots = cat(scatter3d(;x=xyz[:, 1],y=xyz[:, 2], z=xyz[:, 3], mode="markers",
        marker=attr(color="red", size=1, symbol="circle",
            line=attr(color="red", width=1))), dims = 1)
pl = plot(plots, layout; 
    options=Dict(:showLink => true, :toImageButtonOptions => Dict(:format=>"webp")))
display(pl)

let
    for frame in 1:10 
        xyz = rand(10*frame+10, 3)
        plots = cat(scatter3d(;x=xyz[:, 1],y=xyz[:, 2], z=xyz[:, 3], mode="markers",
                marker=attr(color="red", size=3, symbol="circle",
                    line=attr(color="red", width=1))), dims = 1)
        react!(pl, plots, pl.plot.layout)
        sleep(0.5)
        savefig(pl, "a$(f(frame)).png")
    end
end

# Convert to a gif
# magick a*.png a.gif

```

Note that i use ImageMagick to convert the frames into an animation.

---

<div class="post-metadata">

**Author:** ![Oto\_Brzobohaty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oto_brzobohaty/32/10370_2.png) [@Oto\_Brzobohaty](https://discourse.julialang.org/u/Oto_Brzobohaty)\
**Post date:** [June 22, 2021, 7:13pm UTC](https://discourse.julialang.org/t/animation-using-plotlybase/63292/8 "2021-06-22T19:13:16Z")

</div>

Thank you
