# Animate with While loop in Julia

**URL:** <https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069>\
**Category:** Visualization\
**Tags:** plotting, pluto, animations\
**Created:** [May 13, 2021, 8:15am UTC](https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069 "2021-05-13T08:15:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minimum-Pollution-96](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Minimum-Pollution-96](https://discourse.julialang.org/u/Minimum-Pollution-96)\
**Post date:** [May 13, 2021, 8:15am UTC](https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069/1 "2021-05-13T08:15:13Z")

</div>

Is it possible to implement plot animation within while loop in Julia? I’m trying to translate a code that my professor gave me in Matlab. (Top Opt - Sigmund 99 line matlab code)  
It seems both @gif and @animate support only for loops. Since, the iterations to solve the problem depend on problem (and may take long time in case of fine mesh), I’d rather have the plot update per iteration than recording data and using for loop later. But, I just can’t implement it within while loop. Here is a sample for what I’m trying to do.

```julia
using Plots
a = ones(10,10)
i = 1
heatmap(a, c =:grays, framestyle = :none, cbar = false)
while i < 11
    a[i] += i
    i += 1
   heatmap!(a)
   sleep(1e-4)
end

```

I have tried this both in terminal and Pluto. Please let me know if there is way to implement this. Thanks!

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [May 13, 2021, 8:36am UTC](https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069/2 "2021-05-13T08:36:44Z")

</div>

Makie.jl allows for this.  
you can see an example here [https://github.com/triscale-innov/ScreenCastSpring.jl](https://github.com/triscale-innov/ScreenCastSpring.jl) and a related video (in French with English sub-titles) here : [Julia #2/2 : Performance des codes Julia - YouTube](https://www.youtube.com/watch?v=Hy90EsYlEbc)

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 13, 2021, 9:17am UTC](https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069/3 "2021-05-13T09:17:30Z")

</div>

[https://github.com/JuliaPlots/Plots.jl/pull/3497](https://github.com/JuliaPlots/Plots.jl/pull/3497)

---

<div class="post-metadata">

**Author:** ![Minimum-Pollution-96](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Minimum-Pollution-96](https://discourse.julialang.org/u/Minimum-Pollution-96)\
**Post date:** [May 13, 2021, 10:26am UTC](https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069/4 "2021-05-13T10:26:55Z")

</div>

Thanks! Haven’t tried Makie yet but will try it out now!

---

<div class="post-metadata">

**Author:** ![Minimum-Pollution-96](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Minimum-Pollution-96](https://discourse.julialang.org/u/Minimum-Pollution-96)\
**Post date:** [May 13, 2021, 10:27am UTC](https://discourse.julialang.org/t/animate-with-while-loop-in-julia/61069/5 "2021-05-13T10:27:24Z")

</div>

Wow! Thank you sooo much!!
