Creating Animated Makie Plot in Pluto

Hello,

I’d like to embed an animation in my pluto NB. I don’t want to create an MP4 (if possible) - I just want the animation to loop. The animation itself is just a line plot. I tried following the post here. My MWE is below.

begin
    using GLMakie
	# animation settings
	framerate = 30

	# Data is x and y
	# x is a 1-dimensional grid from 0 to 1
	# y is a 100x2 matrix where each element of the second column 
	# is a vector containing the line plot at a different time step

	nframes = 2:length(y[1:end,2])

	fig, ax, pl = lines(x, y[1, 2]) # initial condition

	record(fig, nframes; framerate = framerate) do p
		pl[1] = y[nframes, 2]
	end
end

When I try to run the cell I get the error

MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Float64

If I inspect pl[1] I can see what looks like the plotted points in GeometryBasics.Point but I have no idea how to access them. Perhaps there is something obvious here - if so I apologize, I am new to Makie.

I also tried creating the animation using Observables. Shown below.

begin
	oy = Observable(y[1, 2])
	fig = Figure()
	display(fig)
	ax = Axis(fig[1, 1])
	lines!(ax, x, oy)
	ylims!(ax, 0, 1)

	for time_step = 2:length(y[:, 1])
    	oy[] = y[time_step, 2]
    	sleep(0.1)
	end
end

When I do this I get the following error.

Plot needs to be displayed to insert additional plots

Any hints or ideas on how I can accomplish this? Or where I am going wrong?

I think in the first case Makie is converting your inputs to arrays. You could check pl[1] to see if that’s true and update with pl[1] = [y[nframes, 2]] if it is.

Thanks for the suggestion. I tried it and now I get the error

MethodError: Cannot `convert` an object of type Vector{Any} to an object of type Float64