# Makie doesn't show anything when run as a script

**URL:** <https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664>\
**Category:** General Usage\
**Created:** [April 19, 2023, 4:02pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664 "2023-04-19T16:02:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [April 19, 2023, 4:02pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/1 "2023-04-19T16:02:55Z")

</div>

I am trying to plot something using Makie in the test.jl file. But it doesn’t show figure when using julia test.jl.

Here is my code:

using GLMakie  
xs = cos.(1:0.5:20)  
ys = sin.(1:0.5:20)  
zs = LinRange(0, 3, length(xs))  
a=meshscatter(xs, ys, zs, markersize = 0.1, color = zs)  
display(a)

Thanks for any suggestions.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [April 19, 2023, 4:06pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/2 "2023-04-19T16:06:58Z")

</div>

run it with

```julia
julia -i test.jl

```

basically you need to stop Julia from exiting

---

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [April 19, 2023, 4:12pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/3 "2023-04-19T16:12:22Z")

</div>

thank you, it works by adding “-i”. But I am curious what is the propose of “-i”, it looks like force julia go to the REPL, because after I ran above commend, it jumped into the REPL. I am wondering could I stay in my previous environment. Thanks

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [April 19, 2023, 4:14pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/4 "2023-04-19T16:14:16Z")

</div>

for the display window to stay open, the Julia process can’t exit. You can also put a `readline()` after the `display()` but you still won’t be able to use that terminal session.

`-i` puts you into interactive mode (REPL) after executing the script, which is a way to prevent exiting

---

<div class="post-metadata">

**Author:** ![jianqixi](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jianqixi](https://discourse.julialang.org/u/jianqixi)\
**Post date:** [April 19, 2023, 4:18pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/5 "2023-04-19T16:18:28Z")

</div>

I see, thank you. I am wondering if I add Scene() whether it could help me to stay on terminal. Thanks

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [April 19, 2023, 6:34pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/6 "2023-04-19T18:34:52Z")

</div>

You can also prevent exit by sleeping on the initial task:

```julia
using GLMakie

function main()
    fig = Figure()
    ax = Axis3(fig[1,1])
    xs = cos.(1:0.5:20)
    ys = sin.(1:0.5:20)
    zs = LinRange(0, 3, length(xs))
    a = meshscatter!(ax, xs, ys, zs, markersize = 0.1, color = zs)
    exit = Observable(false)
    exit_button = Button(fig[2,1]; label="Quit", tellwidth=false, tellheight=false)
    on(exit_button.clicks) do _
        exit[] = true
    end
    display(fig)
    while !exit[]
        sleep(0.01)
    end
end

main()

```

Edit In response to the comment below from @albheim, that is indeed a much simpler solution.

```julia
using GLMakie

function main()
    fig = Figure()
    ax = Axis3(fig[1,1])
    xs = cos.(1:0.5:20)
    ys = sin.(1:0.5:20)
    zs = LinRange(0, 3, length(xs))
    a = meshscatter!(ax, xs, ys, zs, markersize = 0.1, color = zs)
    wait(display(fig))
end

main()

```

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [April 19, 2023, 7:24pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/7 "2023-04-19T19:24:40Z")

</div>

On the phone so haven’t tried, but I believe you can also call `wait` on the return from display to wait until the window decides it is done. E.g. `wait(display(fig))`

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [July 27, 2023, 10:45pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/8 "2023-07-27T22:45:08Z")

</div>

i can confirm that `wait(screen)` works, but…

what if you have multiple screens open? is there a way to wait to exit julia when running a GLMakie script until after they are all closed? i tried adding a wait to each, but the first one then became unresponsive to observable events.

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [July 30, 2023, 4:11pm UTC](https://discourse.julialang.org/t/makie-doesnt-show-anything-when-run-as-a-script/97664/9 "2023-07-30T16:11:15Z")

</div>

Hmm, do you have an example?

I tried something like this

```julia
using GLMakie

a = lines(rand(10))
b = scatter(rand(10))

ad = display(GLMakie.Screen(), a)
bd = display(GLMakie.Screen(), b)

wait(ad)
wait(bd)

```

and that seems to be responsive (can zoom in both windows, assume that is some type of observable event?) and the program is only closed when both windows have been closed.
