Makie - plot script returned without visualization window

I see the documentation that it might be a problem of GLMakie building, but my build seems fine without any errors. I also tried build GLMakie, it looks fine.

this is my code for test:

using ModernGL

#using Makie
#using CairoMakie
using GLMakie

x = LinRange(0, 10, 100)
y = sin.(x)
fig = lines(x, y)

display(fig)

NVM, I fixed this using this code.

#using ModernGL

using Makie
# using WGLMakie
# WGLMakie.activate!()
using GLMakie
GLMakie.activate!()

set_window_config!(;
    vsync = false,
    framerate = 30.0,
    float = false,
    pause_rendering = false,
    focus_on_show = false,
    decorated = true,
    title = "Makie"
)


function display3d()
#using CairoMakie
#using GLMakie

    x = LinRange(0, 10, 100)
    y = sin.(x)
    z = cos.(x)

    fig = lines(x, y, z)

    display(fig)
end

display3d()

it is not working again with the same code…
the window shows up for a few seconds, but closed after that. Nothing have showed up in the window.

If you add sleep(15) at the last line you may see the plot. What is happening is that the program is finishing, and when this happens julia exits. Because Makie takes many seconds in showing the first plot, Julia exits before you get to see the plot.

Depending on your use case, you could either pass a -i flag to julia, to make it launch the REPL after your script (julia -i myscript.jl) or add a sleep(30) at the end. However julia is not very well suited for script-based plotting due to the long time to first plot.

Also, you really don’t need the package Makie, ModernGL nor the line GLMakie.activate!(). GLMakie is enough.

To view Makie plots when running a Julia script,

I do the following

. . .

# 1st Makie plot display
display(fig_1)

# Prompt to input from terminal
print("Press any key to contnue. ") 
    
# Call the readline function
readline()

. . .

# 2nd Makie plot display
display(fig_2)

# Prompt to input from terminal
print("Press any key to contnue. ") 
    
# Call the readline function
readline()

. . . 

and so on.

It would be useful if Makie waited until a plot window was closed before continuing as does Matplotlib in Python.

you can use wait(display(fig)) to wait until the window gets closed :wink:

1 Like

wait(display(fig)) is what I needed to know. Thanks.