# How to make plot window stay open when running a .jl script

**URL:** https://discourse.julialang.org/t/how-to-make-plot-window-stay-open-when-running-a-jl-script/23484
**Category:** New to Julia
**Created:** [April 24, 2019, 8:01pm UTC](https://discourse.julialang.org/t/how-to-make-plot-window-stay-open-when-running-a-jl-script/23484 "2019-04-24T20:01:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![phil1](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@phil1](https://discourse.julialang.org/u/phil1)
#### Post date: [April 24, 2019, 8:01pm UTC](https://discourse.julialang.org/t/how-to-make-plot-window-stay-open-when-running-a-jl-script/23484/1 "2019-04-24T20:01:43Z")

</div>

I write a simple script, plotex1.jl to produce a plot;

using Plots  
pyplot() # Switch to using the PyPlot.jl backend  
plot1 = plot(rand(10,10),linewidth=2,title=“Plot 1”)  
display(plot1)

The I run the script from my terminal  
$ julia plotex.jl

I see the plot flash for a split second and then it disappears. How can I make the plot window stay open?

(If I run the code from REPL, the last line is not needed and the plot window shows and stays open)

---

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [April 24, 2019, 8:12pm UTC](https://discourse.julialang.org/t/how-to-make-plot-window-stay-open-when-running-a-jl-script/23484/2 "2019-04-24T20:12:33Z")

</div>

after the plot, add  
`gui()`

alternatively, do  
`display(plot1)`

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [April 24, 2019, 11:23pm UTC](https://discourse.julialang.org/t/how-to-make-plot-window-stay-open-when-running-a-jl-script/23484/3 "2019-04-24T23:23:15Z")

</div>

First, please [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530): this makes it easier to run your examples and help you.

  

As for your question: the problem is that you need Julia to stay alive for it to display the graph. There are two ways (that I know of):

1. run your script like this:

2. add `readline()` at the end of your script. This will make Julia wait until you press RET before it exits (and makes your plot disappear)

---

<div class="post-metadata">

### Author: ![phil1](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@phil1](https://discourse.julialang.org/u/phil1)
#### Post date: [April 25, 2019, 4:42am UTC](https://discourse.julialang.org/t/how-to-make-plot-window-stay-open-when-running-a-jl-script/23484/4 "2019-04-25T04:42:29Z")

</div>

Thanks,

Here is some feedback.

Adding `gui()` or `display(plot1)` alone did not make the plot window stay open. Nor did `readline()` . Adding `readline()` just made the terminal hang until i hit RETURN.

However adding `gui()` and executing the script with  
$julia -i plotex.jl did the trick.

I will post another question under a performance heading as well. When I type the code manually into REPL the plot shows immediately after the last line. When I run the code as a script from a terminal it takes 27 seconds for the plot to appear! Can anyone explain this?
