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
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!