# Animation with start and stop control in Plots.jl?

**URL:** <https://discourse.julialang.org/t/animation-with-start-and-stop-control-in-plots-jl/118729>\
**Category:** Visualization\
**Tags:** package, plotting, visualization, animations\
**Created:** [August 28, 2024, 6:06pm UTC](https://discourse.julialang.org/t/animation-with-start-and-stop-control-in-plots-jl/118729 "2024-08-28T18:06:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [August 28, 2024, 6:06pm UTC](https://discourse.julialang.org/t/animation-with-start-and-stop-control-in-plots-jl/118729/1 "2024-08-28T18:06:22Z")

</div>

Hello.  
I started my experiments on animations using Plots.jl. There is a quite useful webpage: [Animations with Plots.jl (juliafordatascience.com)](https://www.juliafordatascience.com/animations-with-plots-jl/)  
Using `@animate` or `@gif` macros, it’s quite easy to generate animations. However, if I create these animated plots, they just loop indefinitely without stopping. I want to control this behavior by adding “Start” and “Stop” buttons. Is there any simple way to create such control buttons? I guess it’s easier to use `Pluto.jl`. But I am also interested in doing this under `vscode`. Thanks a lot for your help!

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [August 28, 2024, 9:47pm UTC](https://discourse.julialang.org/t/animation-with-start-and-stop-control-in-plots-jl/118729/2 "2024-08-28T21:47:57Z")

</div>

See here how to get an mp4 instead of a gif file from the animation frames:  
[https://discourse.julialang.org/t/having-problems-with-creating-animations-with-plots-jl-grbackend-juno/21876/2](https://discourse.julialang.org/t/having-problems-with-creating-animations-with-plots-jl-grbackend-juno/21876/2).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 29, 2024, 8:36am UTC](https://discourse.julialang.org/t/animation-with-start-and-stop-control-in-plots-jl/118729/4 "2024-08-29T08:36:32Z")

</div>

> [@BVPs](#):
>
> I guess it’s easier to use `Pluto.jl`. But I am also interested in doing this under `vscode`.

If you just want video controls like play/pause then you can probably display a `<video>` tag linking to the local video file generated with Plots.jl in the VSCode plot pane and that would work because VSCode is basically a browser.

But as you mentioned Pluto.jl, it sounds like you might be thinking about some kind of simple UI for controlling animations? Another option for that if you want it to work in VSCode is WGLMakie.jl. Here’s a basic animation of a dataset (and this doesn’t just loop but pulls in new data) with a start and stop button as an example, if you’re interested to go down that road.

---

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [August 29, 2024, 9:44pm UTC](https://discourse.julialang.org/t/animation-with-start-and-stop-control-in-plots-jl/118729/5 "2024-08-29T21:44:32Z")

</div>

Thanks a lot, @jules. But if possible, I want to stick with `Plots.jl`. Also, I want to run the animation under `Pluto.jl`. I found that `gif` function of `Plots.jl` has an input argument called `loop`, which is set to `0` by default. It seems to me that this argument is passed to `ffmpeg`. According to `ffmpeg` documentation, the infinite loop should be specified by `-stream_loop -1`, not `-stream_loop 0`. But at this point, `gif(anim, loop=0)` repeats the animation indefinitely. When I call `gif(anim, loop=1)` instead, it just runs the animation once. But when I click the execution button in `Pluto` notebook for the second time, it doesn’t run animation unless I change some other parameters…
