Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a GIF by using multiple plots of arrays?

Tags:

julia

I want to make simulation of wave packet in free space in Julia and for this purpose I need to store every plot, plotted using arrays, in a frame and then to show it in the form of a simulation of 15 seconds. I have written code for these plots but dont know how to make simulation in which previous line of plot doesn't show and only shows a wave like simulation.

enter code here

function gauss(x, xo)
    exp(-k * (x - xo) ^ 2)
    end
y = zeros(100,15)

k =1000
xo = 0.3
for j = 1:2
    x = 0.0 
    for i = 2:99
        y[i, j] = gauss(x, xo)
        x = x + 0.01
        end
    xo = xo + 0.1
end
y
function z(i, n)
     2 * (1 - (r ^ 2)) * y[i, n] - y[i, n - 1] + (r ^ 2) * (y[i + 1, n] + y[i - 1, n])
end
r = 1
mat= zeros(100,15)
for n = 2:14
    for i = 2:99
        y[i, n+1] = z(i, n)
    end
end
y
using Plots

plot(i=1:100,y[:, 1:15])
like image 955
Salahuddin Ayubi Avatar asked Dec 22 '25 18:12

Salahuddin Ayubi


1 Answers

I understand that you want to combine plotting with an animation (hopefully this is what you mean). In that case you can use an @animate macro:

using Plots
x = 0:π/100:8π
anim =  @animate for v ∈ 0:π/20:2π
    plot(x, sin.(x .+ v), legend=false)
end
 
gif(anim, "myanim.gif", fps = 15)

enter image description here

like image 173
Przemyslaw Szufel Avatar answered Dec 24 '25 11:12

Przemyslaw Szufel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!