I want to use push!()
in a for loop to continue two separate plotting lines. Consider the following example:
using Plots; gr()
f = x->x*x
g = x->f(x)+.2*randn()
p = plot(-1:.1:0, f, ylim=(-1,2), c=:blue)
s = scatter!(-1:.1:0, g, c=:red)
anim = Animation()
for i=1:10
x = i/10
push!(p, x, f(x))
push!(s, x, g(x)) # without this, f gets continued as expected
frame(anim)
end
gif(anim, "test.gif", fps=2)
Why does push!(p, ...)
and push!(s,...)
both continue the blue line?
How to append scattered data to s
instead?
I know that the second plot at this link achieves a similar result by plotting and pushing both lines at once, but that solution is not always practical, especially in more complicated plots.