Open luisaforozco opened 4 months ago
I found that with Makie.jl
you cannot directly create a gif
but an mp4
and then convert it using ffmpeg
.
Performance could be improved by using Makie instead of Plots due to its quick loading time and better speed in generating animations.
Consider for example the following snipped from 03.01
using Plots
anim = Animation()
fig = plot(layout = (3, 1), size = (800, 300))
@gif for i in 1:2:size(u_dns, 3)
p1 = plot(grid_u_dns.x, u_dns[:, 1, i], xlabel = "x", ylabel = "u",
linetype = :steppre, label = "DNS")
plot!(grid_u_les.x, u_les[:, 1, i], linetype = :steppre, label = "LES")
p2 = plot(grid_u_dns.x, u_dns[:, 2, i], xlabel = "x", ylabel = "u",
linetype = :steppre, legend = false)
plot!(grid_u_les.x, u_les[:, 2, i], linetype = :steppre, legend = false)
p3 = plot(grid_u_dns.x, u_dns[:, 3, i], xlabel = "x", ylabel = "u",
linetype = :steppre, legend = false)
plot!(grid_u_les.x, u_les[:, 3, i], linetype = :steppre, legend = false)
title = "Time: $(round((i - 1) * saveat_shock, digits = 2))"
fig = plot(p1, p2, p3, layout = (3, 1), title = title)
frame(anim, fig)
end
if isdir("./plots")
gif(anim, "plots/03.01_Burgers.gif", fps = 10)
else
gif(anim, "examples/plots/03.01_Burgers.gif", fps = 10)
end
It can be replaced by
using GLMakie
Makie.inline!(false)
fig = Figure(resolution = (400, 600))
ax1 = Axis(fig[1, 1], xlabel = "x", ylabel = "u")
ax2 = Axis(fig[2, 1], xlabel = "x", ylabel = "u")
ax3 = Axis(fig[3, 1], xlabel = "x", ylabel = "u")
lines1 = lines!(ax1, grid_u_dns.x, u_dns[:, 1, 1], color = :blue)
lines2 = lines!(ax1, grid_u_les.x, u_les[:, 1, 1], color = :red)
lines3 = lines!(ax2, grid_u_dns.x, u_dns[:, 2, 1], color = :blue)
lines4 = lines!(ax2, grid_u_les.x, u_les[:, 2, 1], color = :red)
lines5 = lines!(ax3, grid_u_dns.x, u_dns[:, 3, 1], color = :blue)
lines6 = lines!(ax3, grid_u_les.x, u_les[:, 3, 1], color = :red)
if isdir("./plots")
plotname = "plots/03.01_Burgers.gif"
else
plotname = "examples/plots/03.01_Burgers.gif"
end
display(fig)
record(fig, plotname, 1:2:size(u_dns, 3), visible=true, loop=0, framerate=10) do i
lines1[1] = grid_u_dns.x
lines1[2] = u_dns[:, 1, i]
lines2[1] = grid_u_les.x
lines2[2] = u_les[:, 1, i]
lines3[1] = grid_u_dns.x
lines3[2] = u_dns[:, 2, i]
lines4[1] = grid_u_les.x
lines4[2] = u_les[:, 2, i]
lines5[1] = grid_u_dns.x
lines5[2] = u_dns[:, 3, i]
lines6[1] = grid_u_les.x
lines6[2] = u_les[:, 3, i]
ax1.title = "Time: $(round((i - 1) * saveat_shock, digits = 2))"
end
or
using GLMakie
Makie.inline!(false)
fig = Figure(resolution = (400, 600))
ax1 = Axis(fig[1, 1], xlabel = "x", ylabel = "u")
ax2 = Axis(fig[2, 1], xlabel = "x", ylabel = "u")
ax3 = Axis(fig[3, 1], xlabel = "x", ylabel = "u")
# Create observables for the y data of the lines
y1 = Observable(u_dns[:, 1, 1])
y2 = Observable(u_les[:, 1, 1])
y3 = Observable(u_dns[:, 2, 1])
y4 = Observable(u_les[:, 2, 1])
y5 = Observable(u_dns[:, 3, 1])
y6 = Observable(u_les[:, 3, 1])
lines1 = lines!(ax1, grid_u_dns.x, y1, color = :blue)
lines2 = lines!(ax1, grid_u_les.x, y2, color = :red)
lines3 = lines!(ax2, grid_u_dns.x, y3, color = :blue)
lines4 = lines!(ax2, grid_u_les.x, y4, color = :red)
lines5 = lines!(ax3, grid_u_dns.x, y5, color = :blue)
lines6 = lines!(ax3, grid_u_les.x, y6, color = :red)
if isdir("./plots")
plotname = "plots/03.01_Burgers.gif"
else
plotname = "examples/plots/03.01_Burgers.gif"
end
display(fig)
record(fig, plotname, 1:2:10, visible=true) do i
y1[] = u_dns[:, 1, i]
y2[] = u_les[:, 1, i]
y3[] = u_dns[:, 2, i]
y4[] = u_les[:, 2, i]
y5[] = u_dns[:, 3, i]
y6[] = u_les[:, 3, i]
ax1.title = "Time: $(round((i - 1) * saveat_shock, digits = 2))"
end
However there are the following problems:
So this basically means that the Makie implementation shown here would not be well integrated into the example notebooks.
If we are able to fix the problem above, I think that using Makie would be a significant improvement.
Plot.jl is a heavy dependency. We would like to explore if using Makie.jl can be a better option.
What are the biggest differences between Makie.jl and Plots.jl?