Animation sine wave

I try to do a simple animation of a travelling sine wave.
My code is

using Pkg
Pkg.add(“Plots”)
using Plots
plotly()
p =zeros(1)
plot(p)
#println(p)
n=10
@gif for i=0:n
push!(p, sin(i/5))
plot!(p)
#println(i, p)
end

Why isn’t this working?
The error code is

LoadError: MethodError: no method matching _show(::IOStream, ::MIME{Symbol(“image/png”)}, ::Plots.Plot{Plots.PlotlyBackend})

Closest candidates are:

_show(::IO, !Matched::MIME{Symbol(“text/html”)}, ::Plots.Plot) at C:\Users\Gebruiker.julia\packages\Plots\QYETN\src\output.jl:163

_show(::IO, !Matched::MIME{Symbol(“text/plain”)}, ::Plots.Plot) at C:\Users\Gebruiker.julia\packages\Plots\QYETN\src\output.jl:204

_show(::IO, !Matched::MIME{Symbol(“application/vnd.plotly.v1+json”)}, ::Plots.Plot{Plots.PlotlyBackend}) at C:\Users\Gebruiker.julia\packages\Plots\QYETN\src\backends\plotly.jl:857

in expression starting at D:\ScTEXa\Biblio\Programming\Julia\Tests\test3:9

show(::IOStream, ::MIME{Symbol(“image/png”)}, ::Plots.Plot{Plots.PlotlyBackend}) at output.jl:198

png(::Plots.Plot{Plots.PlotlyBackend}, ::String) at output.jl:8

frame(::Animation, ::Plots.Plot{Plots.PlotlyBackend}) at animation.jl:20

frame(::Animation) at animation.jl:18

macro expansion at animation.jl:144 [inlined]

macro expansion at test3:11 [inlined]

top-level scope at animation.jl:155

Thanks Peter

using Plots
gr()
n=100
p =zeros(n)
plot(legend=false, xlims=[0,n], ylims=[-1.1,1.1])
an = @animate for i in 1:n
    p[i] = sin(i/5)
    plot!(p[1:i], color=:black)
end
gif(an, "sine.gif", fps = 40)

sine

1 Like