How to animate a plot with subplots

using Plots

x_data = range(0.0,stop=2π, length=1000)
y_data = sin.(x_data) .+ 0.1.*randn(1000,100)

@gif for i ∈ 1:100
    fig = plot(layout = grid(2,1), legend=false)

    plot!(fig[1], # ADD !
        x_data, y_data)
    vline!([x_data[i]])

    histogram!(fig[2],y_data[i,:],
    xlim=(-1.2,1.2), ylim=(0,50)) # Also added to make it less jumpy.
end

download (1)

2 Likes