Need help animating a plot

I have a simple line plot that I would like to animate.
An array with the number of iterations and the associated array with a value associated with the current iteration.

iters = [x for x in 1:100];
vals = rand(100);

I simply want to animate the development of vals output at each iteration - tiers.
How can I do this in Julia?

using Plots.jl? Animations · Plots

I don’t mind whichever plotting library. I looked at that page but I couldn’t really connect much with the example given hence why I am here.

if you want to plot for each val and animate, just

@gif for i in vals
    plot(...use your i here like you normally would...)
end
1 Like

You can use a slider with Interact.jl, or in the pluto notebook.

2 Likes

Going by this template, I did this which fails miserably:

@gif for i in vals
    plot(i)
end

Any pointers?

That’s also a very interesting approach. How would that work with this basic example?

Is this what you’re after?

using Plots
vals = rand(100)
@gif for i in eachindex(vals)
    plot(vals[1:i])
end
2 Likes

Yes! Small typo plot(vals(1:i)) should be plot(vals[1:i]), right?

Correct, fixed it.

Thanks for your time and tips :slight_smile: