# Fast Replotting

**URL:** <https://discourse.julialang.org/t/fast-replotting/24042>\
**Category:** Performance\
**Tags:** plotting\
**Created:** [May 9, 2019, 5:51pm UTC](https://discourse.julialang.org/t/fast-replotting/24042 "2019-05-09T17:51:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjack205](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjack205/32/7294_2.png) [@bjack205](https://discourse.julialang.org/u/bjack205)\
**Post date:** [May 9, 2019, 5:51pm UTC](https://discourse.julialang.org/t/fast-replotting/24042/1 "2019-05-09T17:51:40Z")

</div>

I can’t figure out the best way to continuously update a plot. I’ve dug around but haven’t found a good example of how to do this, yet.

My use case is running simulations of dynamical systems, and I’d like to see how the system is changing while the code is running. For example

```julia
 using Plots

n,m = 3,2
function dynamics(x,u)
    return [x[1] - x[2] + u[1];
            x[2] + u[1]*u[2]
            x[3]*x[2]/x[1]^2]
end

N = 25
U = [rand(m) for k = 1:N]

function simulate_dynamics(x0, U)
    x = x0
    for k = 1:length(U)
        x = dynamics(x,U[k])
        p = scatter([x[1]],[x[2]],xlim=[-100,100],ylim=[-100,100],markersize=5)
        display(p)
    end
end

simulate_dynamics(rand(3), U)

```

I’d really like to see a “live plot” of the system changing during the simulation, rather than run the whole thing and plot it afterwards.

I’ve found topics that show how to append data to a series using `push!` but haven’t found one for just replacing the data. Any tips on good ways to do this would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 9, 2019, 7:01pm UTC](https://discourse.julialang.org/t/fast-replotting/24042/2 "2019-05-09T19:01:12Z")

</div>

You should really give Makie.jl a shot, it’s prefect for these kind of things (via Observables.jl).

---

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [May 9, 2019, 7:19pm UTC](https://discourse.julialang.org/t/fast-replotting/24042/3 "2019-05-09T19:19:35Z")

</div>

Here are some examples I collected for the same purpose (for Makie):  
[Makie issue 270](https://github.com/JuliaPlots/Makie.jl/issues/270), [Makie issue 279](https://github.com/JuliaPlots/Makie.jl/issues/279), [https://discourse.julialang.org/t/live-plotting-best-practices/16571](https://discourse.julialang.org/t/live-plotting-best-practices/16571)
