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.
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?
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:
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.