# Display images in real time

**URL:** <https://discourse.julialang.org/t/display-images-in-real-time/129580>\
**Category:** Visualization\
**Tags:** plots, makie\
**Created:** [June 2, 2025, 7:16pm UTC](https://discourse.julialang.org/t/display-images-in-real-time/129580 "2025-06-02T19:16:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![homocarbonis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocarbonis/32/223614_2.png) [@homocarbonis](https://discourse.julialang.org/u/homocarbonis)\
**Post date:** [June 2, 2025, 7:16pm UTC](https://discourse.julialang.org/t/display-images-in-real-time/129580/1 "2025-06-02T19:16:19Z")

</div>

I have some code which updates a matrix and I would like to display it as an image which updates in real time. I first tried Plots’ @gif which produces a gif file but no live display, so I switched to Makie. This is my code. It is updating `im` but I can’t find a way to make it actually display the new data.

```julia
S = rand(Float64,(32,32))
fig,ax,im = image(S)
display(fig)
for i in 1:10
    sweep(S)
    im[3].val = S
    yield()
end

```

I’m not attached to any particular library if there is a better way of doing this.

---

<div class="post-metadata">

**Author:** ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Post date:** [June 2, 2025, 7:26pm UTC](https://discourse.julialang.org/t/display-images-in-real-time/129580/2 "2025-06-02T19:26:11Z")

</div>

Use Observables.jl with GLMakie.jl.

Simple example below:

```julia
using GLMakie
using Observables

fig = Figure()
ax = Axis(fig[1,1])

x = Observable(randn(32, 32))
image(x)

for i = 1:10
    x[] = randn(32, 32)
    sleep(0.1)
end

```

---

<div class="post-metadata">

**Author:** ![homocarbonis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocarbonis/32/223614_2.png) [@homocarbonis](https://discourse.julialang.org/u/homocarbonis)\
**Post date:** [June 2, 2025, 7:38pm UTC](https://discourse.julialang.org/t/display-images-in-real-time/129580/3 "2025-06-02T19:38:13Z")

</div>

Thank you, that has got me to a working solution. I had looked at Observables but I couldn’t see how to make them work when the data is modified in place.

Working code:

```julia
S = rand(Float64,(32,32))
X = Observable(S)
image(X)

for i in 1:10
    X[]=sweep(S)
    sleep(0.1)
end

```

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [June 2, 2025, 8:36pm UTC](https://discourse.julialang.org/t/display-images-in-real-time/129580/4 "2025-06-02T20:36:57Z")

</div>

You can use [`notify()`](https://juliagizmos.github.io/Observables.jl/stable/#Base.notify-Tuple%7BAbstractObservable%7D) to trigger an update after an in-place modification:

```julia
S = rand(Float64,(32,32))
X = Observable(S)
image(X)

function sweep!(x)
  x[9:24, 9:24] = rand(Float64, (16, 16))
  nothing
end

for i in 1:10
    sweep!(S)
    notify(X)
    sleep(0.1)
end

```
