Combine a "plot" object with a "scatter" object in an animation

I don’t know how to do that using Plots, but here’s an example using Gaston and gnuplot. I couldn’t reproduce your code exactly because I don’t know what V(x) is, but my example should be easy to adapt.

using Gaston
x = -5:0.1:5;
y = sin.(π*x);
F = plot(x, y, lc = :black);  # we need one first plot
for (idx, xx) in enumerate(x)
    # plot "trajectory"
    P = plot(x, y, lc = :black, handle = 2);
    # plot "particle"
    plot!([xx], [y[idx]], w = :points,
          marker = "fcircle", markersize = 3,
          lc = :blue, handle = 2);
    push!(F, P)  # add new frame to first plot
end
# save as gif
save(term = "gif",
     saveopts = "animate size 600,400 delay 1",
     output = "anim.gif", handle = 1)

anim

2 Likes