4

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.

logankilpatrick
  • 13,148
  • 7
  • 44
  • 125

1 Answers1

4

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)

Inital plot

sleep(10)
pop!(scene.plots)
display(scene)

2nd image

sleep(10)
pop!(scene.plots)
display(scene)

3rd picture

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.

Docs for sleep()

This might also be a good reference example for this post.

logankilpatrick
  • 13,148
  • 7
  • 44
  • 125