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

The following code ran and successfully showed “OK2”, but the graph didn’t show up. Why?

using Plots
using NURBS
using PlotlyJS
using StaticArrays

P0 = SVector(0.0 , 1.0, 0.0)
P1 = SVector(0.25, 1.0, 0.0)
P2 = SVector(0.5 , 1.0, 0.0)
P3 = SVector(0.75, 1.0, 0.0)
P4 = SVector(1.0 , 1.0, 0.0)
control_points = [P0, P1, P2, P3, P4]

degree=3

weights = [1.0, 1.0, 1.0, 1.0, 1.0]

knot_vector = Float64[0, 0, 0, 0, 1, 2, 2, 2, 2]
knot_vector ./= maximum(knot_vector)

println("control_points: ",control_points)

NCurve = NURBScurve(NURB(degree, knot_vector, weights), control_points)

show_points = collect(0:0.1:1.0)
println("show_points: ",show_points)
CNurbs = NCurve(show_points)
println("OK1: ", CNurbs)

plotCurve3D(CNurbs, controlPoints=control_points)
println("OK2")

The code finished running, but I see from the vscode problems window, there is a IncorrectCallArgs in plotCurve3D line.

Please help out!

Your code works for me, both in VS Code and in a standard terminal. Could you check if the issue persists when not using VS Code?

(By the way, if you’re not running this line by line, you should use display(plotCurve3D(...)).)

Thanks, the display() function works in vscode, but I still need add

sleep(60)

then, it showed up for 60 seconds, and close automatically.

Actually, the process will sleep for exactly 60 seconds even if you close the graph window manually.

Why does it behave like this? Shouldn’t it appear automatically and stay visible until I manually close the window?

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

I see, thanks alot!

1 Like