Efficient heatmap/general data updating

I am making a gif of diffusion using a series of heatmaps, and come from a Matlab background. In that environment, it was far more efficient to directly set the z-data of a current plot instead of redrawing the plot after every few iterations.

I want to know how to do this most efficiently in Julia. plot!() appends to an existing plot, but I cannot find the correct command to change current data, if it exists. What is the best way to change current data in an existing plot, especially the z/c data for a heatmap?


1 Like

you want Plots.display(Plots.heatmap(rand(10,10)))?

Most of the plot commands have in-place versions a la

p = plot(rand(10))
plot!(p[1], rand(10))

This is pretty quick:

function heatgif(A::AbstractArray{<:Number,3}; kwargs...)
    p = heatmap(zeros(size(A, 1, 2)); kwargs...)
    anim = @animate for i=1:size(A,3)
        heatmap!(p[1], A[:,:,i])
    return anim
anim = heatgif(rand(10,10,10))
gif(anim, "/tmp/anim_fps15.gif", fps = 15)