I want to be able to pause my program in order to give a Makie.jl window time to render on the screen so I can see what the changes I am making to it are. How can I do this.
1 Answers
The simple answer is to use sleep(t)
where t
is the time in seconds you sleep or more formally, the time duration for which you want to block the curent task from running. A fun example that highlights the power of sleep()
is as follow:
using Makie
x = range(0, stop = 2pi, length = 80)
f1(x) = sin.(x)
f2(x) = exp.(-x) .* cos.(2pi*x)
y1 = f1(x)
y2 = f2(x)
scene = lines(x, y1, color = :blue)
scatter!(scene, x, y1, color = :red, markersize = 0.1)
lines!(scene, x, y2, color = :black)
scatter!(scene, x, y2, color = :green, marker = :utriangle, markersize = 0.1)
display(scene)
sleep(10)
pop!(scene.plots)
display(scene)
sleep(10)
pop!(scene.plots)
display(scene)
You can see the images above that show how the plot progressively gets undone using pop()
. The key idea with respect to sleep()
is that if we were not using it (and you can test this on your own by running the code with it removed), the fist and only image shown on the screen will be the final image above because of the render time.
You can see if you run this code that the window renders and then sleeps for 10 seconds (in order to give it time to render) and then uses pop!()
to step back through the plot.
This might also be a good reference example for this post.

- 13,148
- 7
- 44
- 125