# Deactivate plot display to avoid need for X server

**URL:** https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359
**Category:** Visualization
**Tags:** question
**Created:** [January 7, 2019, 6:19pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359 "2019-01-07T18:19:25Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![samo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samo/32/35398_2.png) [@samo](https://discourse.julialang.org/u/samo)
#### Post date: [January 7, 2019, 6:19pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/1 "2019-01-07T18:19:25Z")

</div>

I use the following type of code to create a gif animation:

```julia
using Plots
anim = Animation();
for it = 1:nt
      contourf(...);
      frame(anim);
end
gif(anim, "test.gif", fps = 15);

```

This works fine on my local notebook or when I connect to a compute node with X server (ssh -X). However, I need to be able to do that without any X server (for distributed jobs). When I run it without an X server available, I get the following error:

```bash
gksqt: cannot connect to X server localhost:12.0
connect: Connection refused
GKS: can't connect to GKS socket application
Did you start 'gksqt'?

GKS: Open failed in routine OPEN_WS
GKS: GKS not in proper state. GKS must be either in the state WSOP or WSAC in routine ACTIVATE_WS

```

Could you tell me how to avoid the need for an X server, i.e. how I can deactivate any display / how I can deactivate GKS?

Thanks!

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [January 7, 2019, 6:49pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/2 "2019-01-07T18:49:07Z")

</div>

You can set the output type before using the `gr` backend using `ENV["GKSwstype"]=100` or ` `ENV[“GKSwstype”]=“nul”`, which activates the NULL device.

---

<div class="post-metadata">

### Author: ![samo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samo/32/35398_2.png) [@samo](https://discourse.julialang.org/u/samo)
#### Post date: [January 8, 2019, 8:18am UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/3 "2019-01-08T08:18:07Z")

</div>

Great setting `ENV["GKSwstype"]="nul"` makes it work! Thank you very much!

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [January 22, 2019, 5:29pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/4 "2019-01-22T17:29:44Z")

</div>

> [@samo](#):
>
> ENV[“GKSwstype”]=“nul”

I had a hard time to solve this issue until I found this post. Thank you very much.

At the same time, it would be nice if there was a less hackier way to do it, something like

`plot!(display=none)`

Don’t you think?

---

<div class="post-metadata">

### Author: ![samo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samo/32/35398_2.png) [@samo](https://discourse.julialang.org/u/samo)
#### Post date: [January 30, 2019, 4:38pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/5 "2019-01-30T16:38:23Z")

</div>

Yes @lmiq, I totally agree: it would be good if one could turn off the display with a function call.

---

<div class="post-metadata">

### Author: ![JeffFessler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jefffessler/32/6650_2.png) [@JeffFessler](https://discourse.julialang.org/u/JeffFessler)
#### Post date: [July 9, 2019, 6:21pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/6 "2019-07-09T18:21:15Z")

</div>

Something close to what you want is this:

using Plots: default  
default(show=false)

I learned it from the Plots.jl runtests.jl file:

> <https://github.com/JuliaPlots/Plots.jl/blob/master/test/runtests.jl>

But I still needed to set ENV as well…

---

<div class="post-metadata">

### Author: ![samo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samo/32/35398_2.png) [@samo](https://discourse.julialang.org/u/samo)
#### Post date: [July 12, 2019, 7:20am UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/7 "2019-07-12T07:20:12Z")

</div>

Thanks @JeffFessler for your comment. As you note what actually solves the problem is the environment variable though…

---

<div class="post-metadata">

### Author: ![LolianSh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loliansh/32/10834_2.png) [@LolianSh](https://discourse.julialang.org/u/LolianSh)
#### Post date: [February 26, 2020, 10:48pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/8 "2020-02-26T22:48:54Z")

</div>

How could you reset ENV[“GKSwstype”] to its default value again after having set ENV[“GKSwstype”]=“nul” in the same julia session?

I ask because I would like to disable the prompting of plots only for a specific part of the code, and then return to the default state.

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [February 27, 2020, 4:39am UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/9 "2020-02-27T04:39:33Z")

</div>

You can remove or reset the environment variable with `delete!(ENV, "GKSwstype")` or `ENV["GKSwstype"] = ""` and then force `GR` to reload its graphics subsystem using `GR.emergencyclosegks()` (or `Plots.GR.emergencyclosegks()` in `Plots`.)

---

<div class="post-metadata">

### Author: ![mfariacastro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfariacastro/32/4432_2.png) [@mfariacastro](https://discourse.julialang.org/u/mfariacastro)
#### Post date: [May 1, 2020, 8:57pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/10 "2020-05-01T20:57:34Z")

</div>

Just came here to say THANK YOU! I am running scripts on an external server that generate figures saved as pdf. The script prints a log file with diagnostics, and those log files were 95% errors related to GKS and GR from trying to plot the figures on the server. This thread finally solved my problem!

---

<div class="post-metadata">

### Author: ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)
#### Post date: [May 25, 2020, 9:19pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/11 "2020-05-25T21:19:28Z")

</div>

Would you help me.  
Why I have the problem.  
This code doesn’t work, Plot rise a error (with very long message)

```julia
using Plots
ENV["GKSwstype"]="nul"
gr()
x=[1:10]
y=2*x
plot(y,x)

```

---

<div class="post-metadata">

### Author: ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)
#### Post date: [May 20, 2021, 11:38pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/12 "2021-05-20T23:38:13Z")

</div>

I have the same . did you reach any solution???

---

<div class="post-metadata">

### Author: ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)
#### Post date: [May 22, 2021, 4:50pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/13 "2021-05-22T16:50:13Z")

</div>

it looks like I didn’t use gt().

I’ve check right now. The following code has done perfectly.

```julia
using Plots
ENV["GKSwstype"]="nul"
plot(rand(100,1))
Plots.savefig("test.png")

```

---

<div class="post-metadata">

### Author: ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)
#### Post date: [May 28, 2021, 2:06pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/14 "2021-05-28T14:06:28Z")

</div>

Thanks for the response

---

<div class="post-metadata">

### Author: ![jbcaillau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbcaillau/32/206767_2.png) [@jbcaillau](https://discourse.julialang.org/u/jbcaillau)
#### Post date: [February 19, 2023, 8:38pm UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/15 "2023-02-19T20:38:25Z")

</div>

Thanks for this useful post. As others above, I believe something as simple as

```julia
plot(x, y, file="foo.svg")

```

(or an explicit display change…) that would override display on stdout would be a welcome addition.

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [May 9, 2023, 8:47am UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/16 "2023-05-09T08:47:48Z")

</div>

years later I am running into the same problem, but using plotly() backend which tries to open a html plot with xdg-open and fails

```julia
ERROR: failed process: Process(`xdg-open /tmp/jl_RGBaJUX69S.html`, ProcessExited(3)) [3]

```

How can I make silently ignore this?

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [May 9, 2023, 9:37am UTC](https://discourse.julialang.org/t/deactivate-plot-display-to-avoid-need-for-x-server/19359/17 "2023-05-09T09:37:54Z")

</div>

I now create a dummy xdg-open and put it before the path. Seems to have worked.

Also, suprisingly, when I simply run a julia files `myfile.jl` which uses normal plot(…) commands using `julia myfile.jl`, no error is thrown. Looks like `Plots` already comes with some display logic depending on how it is started
