# Creating a real-time film

**URL:** <https://discourse.julialang.org/t/creating-a-real-time-film/79467>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [April 14, 2022, 5:15am UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467 "2022-04-14T05:15:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [April 14, 2022, 5:15am UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/1 "2022-04-14T05:15:57Z")

</div>

Hi. I’m relatively new to Julia, but I’m writing a course for students that involves animating plots, so for example plotting a sequence of graphs showing a sine curve that is successively moved to the right, so that it creates an impression of a moving wave. So what I really need is a way of repainting the contents of an existing figure without completely replacing the figure. However, I just can’t seem to find what I need.

I’m afraid I don’t even know the right word for what I’m looking for. When I look up “animation”, that seems to mean creating a complete gif, but for my more complex systems, that would mean accumulating large amounts of data that I don’t need: I only want to see the current state of the system, and throw away the past.

Can anyone help?

Thanks,  
Niall.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 14, 2022, 5:51am UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/2 "2022-04-14T05:51:34Z")

</div>

Have you seen GLMakie for example? [Animations](https://makie.juliaplots.org/stable/documentation/animation/#animations_using_observables)

You can record such animations or just let them play while looking at them

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [April 14, 2022, 11:30am UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/3 "2022-04-14T11:30:24Z")

</div>

Thanks very much - that looks like just what I’m looking for.

I am surprised, though, that it seems such a big deal. In Matlab I was used to simply redrawing a figure, but here I need to used dedicated macros and Observables. How does that come about?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 14, 2022, 11:39am UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/4 "2022-04-14T11:39:48Z")

</div>

It’s not a big deal really, Observables are a way of making it easier to let information changes flow to the display.

The minimal example for the sine would be:

```julia
phase = Observable(0.0)

x = 0:0.01:10
y = lift(phase) do p
    @. sin(x - p)
end

fig, ax, lin = lines(x, y)
display(fig)

for _phase in 0:0.1:10
    phase[] = _phase
    sleep(1/60)
end

```

So you update `phase`, which updates `y`, which updates the plot.

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [April 14, 2022, 11:50am UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/5 "2022-04-14T11:50:07Z")

</div>

Great - thanks a lot. I’ll have to look into this. 😁

---

<div class="post-metadata">

**Author:** ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)\
**Post date:** [April 14, 2022, 4:23pm UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/6 "2022-04-14T16:23:06Z")

</div>

Just checking, but should that `phase` inside the loop be `_phase`?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 14, 2022, 5:27pm UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/7 "2022-04-14T17:27:38Z")

</div>

Ah yeah good point, didn’t run that 🙂

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [April 15, 2022, 1:35pm UTC](https://discourse.julialang.org/t/creating-a-real-time-film/79467/8 "2022-04-15T13:35:52Z")

</div>

Hey, that’s really neat - thanks a lot. Plus the code has a bunch of features that are new to me and it’ll be fun working them out. 😃
