Why the plotCurve3D didn't show up while the code finished running?

This all depends on exactly how you run your script. It seems like you’re using something akin to julia script.jl. In that case Julia will go through your script and terminate after having executed the last line. Because the plotting window runs asynchronously (in contrast to sleep), Julia will open the window, but immediately move on to the next line. When Julia soon after reaches the end of the script and terminates, the plotting window also closes.

If you run your script in interactive mode via julia -i script.jl, Julia will not close and you can keep interacting with the plot. Alternatively, you can use include("script.jl") into an active REPL. Within VS Code you have Julia: Execute (Active) File in REPL.

As a sidenote, I would have expected there to be a plot(..., block=true) option, as in Python’s matplotlib, but that doesn’t seem to be the case. This would halt Julia at the plotting code line, so that we don’t reach the end and exit. You could then also use @spawn/@async display(plot(..., block=true)) and wait at the end of the script to wait there until the window has been closed. But again, no block keyword seems to exist. A ‘workaround’ I’ve seen suggested is to use readline() to block the main (IO) thread.

1 Like