# Efficient heatmap/general data updating

**URL:** <https://discourse.julialang.org/t/efficient-heatmap-general-data-updating/11203>\
**Category:** Performance\
**Created:** [May 28, 2018, 3:27pm UTC](https://discourse.julialang.org/t/efficient-heatmap-general-data-updating/11203 "2018-05-28T15:27:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oz\_Wilson](https://avatars.discourse-cdn.com/v4/letter/o/ea666f/32.png) [@Oz\_Wilson](https://discourse.julialang.org/u/Oz_Wilson)\
**Post date:** [May 28, 2018, 3:27pm UTC](https://discourse.julialang.org/t/efficient-heatmap-general-data-updating/11203/1 "2018-05-28T15:27:25Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 28, 2018, 6:13pm UTC](https://discourse.julialang.org/t/efficient-heatmap-general-data-updating/11203/2 "2018-05-28T18:13:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [May 28, 2018, 6:53pm UTC](https://discourse.julialang.org/t/efficient-heatmap-general-data-updating/11203/3 "2018-05-28T18:53:28Z")

</div>

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

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

```

This is pretty quick:

```julia
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])
    end
    return anim
end

```

```julia
anim = heatgif(rand(10,10,10))
gif(anim, "/tmp/anim_fps15.gif", fps = 15)

```
