# How to get a plot to stay open?

**URL:** <https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [April 14, 2018, 5:55pm UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338 "2018-04-14T17:55:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![han-so1omon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/han-so1omon/32/4398_2.png) [@han-so1omon](https://discourse.julialang.org/u/han-so1omon)\
**Post date:** [April 14, 2018, 5:55pm UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/1 "2018-04-14T17:55:41Z")

</div>

How to get a plot to stay open? `gui()`, `display()`, and `<plot_impl>(show=true)` all cause plot to close immediately. Except for in Julia REPL, where plot stays open forever and does not respond to close command. Using v0.6.2 on Ubuntu

Edit: Minimum working example

> using Plots  
> gr(show = true)  
> p1 = plot(1:10,1:10)  
> #display(p1)  
> gui(p1)

Edit2: Using `Blink Atomshell` with PlotlyJS works  
Edit3: Minor formatting fixes

---

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [April 16, 2018, 6:53am UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/2 "2018-04-16T06:53:48Z")

</div>

I’m assuming you are plotting from a julia script and using terminal to call `julia script.jl`.  
The problem is once your execution is finished, julia exists and hence the plot also closes.  
You can try adding `read(STDIN, Char)` after plot, or better at the end of the script. This will make the plot stay until you press enter.

> [@han-so1omon](#):
>
> plot stays open forever and does not respond to close command

I also have the similar problem; when I click close button it didn’t work. I usually do `close("all")` in REPL to close them. OR `close(fig_num)` can also be used.

---

<div class="post-metadata">

**Author:** ![han-so1omon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/han-so1omon/32/4398_2.png) [@han-so1omon](https://discourse.julialang.org/u/han-so1omon)\
**Post date:** [April 18, 2018, 2:16am UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/3 "2018-04-18T02:16:49Z")

</div>

neither `close("all")` nor `close(:all)` close the window

---

<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:** [April 22, 2018, 11:24pm UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/4 "2018-04-22T23:24:27Z")

</div>

a minimal code snippet always helps with such questions. you’ve given us no idea, for example, of which of the many plotting packages you’re using.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 23, 2018, 8:21am UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/5 "2018-04-23T08:21:37Z")

</div>

Doesn’t `gr(show = true)` means that GR is used?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 23, 2018, 9:27am UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/6 "2018-04-23T09:27:27Z")

</div>

That was not in the original version of the message.

---

<div class="post-metadata">

**Author:** ![han-so1omon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/han-so1omon/32/4398_2.png) [@han-so1omon](https://discourse.julialang.org/u/han-so1omon)\
**Post date:** [April 23, 2018, 4:41pm UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/7 "2018-04-23T16:41:45Z")

</div>

The code section is the minimum working example, which as @dpsanders says was added as an edit. This behavior is not specific to `GR`. With `Plotly`, extra plots are generated in browser. In this case two plots are generated even though there is only one `plot()` call. This behavior seems like a different issue.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [April 23, 2018, 5:43pm UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/8 "2018-04-23T17:43:33Z")

</div>

How do you run this code? As mentioned above, you can run either from REPL, Juno or Jupyter and the plot will stay open whereas if you run from a script (typing `julia script.jl` in the terminal), the GUI will close as soon as Julia exits: this is not the recommended way to use Plots.

To close all window you can use `closeall()`.

---

<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:** [April 28, 2018, 1:41pm UTC](https://discourse.julialang.org/t/how-to-get-a-plot-to-stay-open/10338/9 "2018-04-28T13:41:56Z")

</div>

would [Gtk.jl’s trick](https://github.com/JuliaGraphics/Gtk.jl#usage-without-the-repl) work?
