# Gks Error When Plotting in VS Code

**URL:** https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618
**Category:** VS Code
**Tags:** juno, vscode, qt, gr
**Created:** [March 27, 2020, 10:16pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618 "2020-03-27T22:16:38Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [March 27, 2020, 10:16pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/1 "2020-03-27T22:16:38Z")

</div>

The following GKS error is thrown when plotting in vscode. When I try the same plot in Juno or Linux bash terminal no error is thrown. I understand the problem is not directly related to julia-vscode extension but is caused by some kind of Qt error. I am using GR as the backend of Plots and I have already installed additional dependencies of GR for Debian/Linux.

- `apt install libxt6 libxrender1 libxext6 libgl1-mesa-glx libqt5widgets5`

I am particularly surprised that this error is thrown when I try to plot in vscode only. No error is thrown in Linux bash terminal or Juno.

Any ideas on how to fix this?

```julia
julia> using Plots 

julia> plot()
qt.qpa.screen: QXcbConnection: Could not connect to display 
Could not connect to any X display.
connect: Connection refused
GKS: can't connect to GKS socket application

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
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine FILLAREA
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine FILLAREA
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine POLYLINE
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT
GKS: GKS not in proper state. GKS must be either in the state WSAC or SGOP in routine TEXT

```

---

<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: [March 28, 2020, 3:14am UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/2 "2020-03-28T03:14:22Z")

</div>

You probably have to `sudo apt-get install libx11-xcb1`.

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [March 28, 2020, 4:36am UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/3 "2020-03-28T04:36:10Z")

</div>

> [@jheinen](#):
>
> You probably have to `sudo apt-get install libx11-xcb1`

`libx11-xcb1` is already installed in the system.

```bash
$ sudo apt install libx11-xcb1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libx11-xcb1 is already the newest version (2:1.6.4-3ubuntu0.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

```

Here are the locations of `libx11-xcb1` in the system

```bash
$ locate libx11-xcb1
/snap/atom/247/usr/share/doc/libx11-xcb1
/snap/atom/247/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/snap/atom/247/usr/share/doc/libx11-xcb1/copyright
/snap/atom/248/usr/share/doc/libx11-xcb1
/snap/atom/248/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/snap/atom/248/usr/share/doc/libx11-xcb1/copyright
/snap/spotify/36/usr/share/doc/libx11-xcb1
/snap/spotify/36/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/snap/spotify/36/usr/share/doc/libx11-xcb1/copyright
/snap/spotify/41/usr/share/doc/libx11-xcb1
/snap/spotify/41/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/snap/spotify/41/usr/share/doc/libx11-xcb1/copyright
/snap/sublime-text/77/usr/share/doc/libx11-xcb1
/snap/sublime-text/77/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/snap/sublime-text/77/usr/share/doc/libx11-xcb1/copyright
/snap/sublime-text/85/usr/share/doc/libx11-xcb1
/snap/sublime-text/85/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/snap/sublime-text/85/usr/share/doc/libx11-xcb1/copyright
/usr/share/doc/libx11-xcb1
/usr/share/doc/libx11-xcb1/changelog.Debian.gz
/usr/share/doc/libx11-xcb1/copyright
/var/lib/dpkg/info/libx11-xcb1:amd64.list
/var/lib/dpkg/info/libx11-xcb1:amd64.md5sums
/var/lib/dpkg/info/libx11-xcb1:amd64.shlibs
/var/lib/dpkg/info/libx11-xcb1:amd64.triggers
/var/lib/dpkg/info/libx11-xcb1:i386.list
/var/lib/dpkg/info/libx11-xcb1:i386.md5sums
/var/lib/dpkg/info/libx11-xcb1:i386.shlibs
/var/lib/dpkg/info/libx11-xcb1:i386.triggers

```

---

<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: [March 28, 2020, 6:42am UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/4 "2020-03-28T06:42:01Z")

</div>

Can you reproduce the behaviour with plain GR?

```julia
using GR
plot(randn(10))

```

If so, could you try to explicitly switch to SVG or PNG output:

```julia
using GR
inline("svg")
plot(randn(10))

```

`VSCode` should now create an inline plot, right?

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [March 28, 2020, 11:10am UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/5 "2020-03-28T11:10:38Z")

</div>

Yes. A svg plot is created in VSCode. I can also switch to png. But the plots are not the same as those when I plot them in bash terminal. Specifically, the grids and backgrounds are different.

Here is the case when I plot in VSCode.

```julia
julia> using GR 

julia> inline("svg")
"svg"

julia> plot(rand(10))

julia> inline("png")
"png"

julia> plot(rand(10))

```

 ![gr_plots](https://global.discourse-cdn.com/julialang/original/3X/5/b/5b82cab6b2a803ae61133e2ac69bd4440fa0a82b.png)  
and this is the case when I plot in bash terminal.

```julia
$julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.4.0 (2020-03-21)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using GR 

julia> plot(rand(10))
qt5ct: using qt5ct plugin

```

 ![bash_plot](https://global.discourse-cdn.com/julialang/original/3X/8/1/81c1ee9ec5b734ed91690f6b352cba340dc65b22.png)

---

<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: [March 28, 2020, 2:24pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/6 "2020-03-28T14:24:50Z")

</div>

In VSCode, you will have to change the color theme, e.g.

```julia
using GR
usecolorscheme(2)
...

```

In Plots - if not done automatically - you could use:

```julia
Plots.GR.usecolorscheme(2)

```

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [March 28, 2020, 2:43pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/7 "2020-03-28T14:43:10Z")

</div>

I am grateful for your replies @jheinen. Now, When I changed the color theme as you suggested,

> [@jheinen](#):
>
> In VSCode, you will have to change the color theme, e.g.
> 
> ```julia
> using GR
> usecolorscheme(2)
> ...
> 
> ```

every thing looks fine with plain GR. But, still I cannot use Plots. Do you think this is an error on Plots’ side?

---

<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: [March 28, 2020, 2:56pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/8 "2020-03-28T14:56:45Z")

</div>

Are you probably using a different version of GR in Plots?

```julia
using GR
version()

```

should be the same as

```julia
using Plots
Plots.GR.version()

```

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [March 28, 2020, 2:58pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/9 "2020-03-28T14:58:12Z")

</div>

I am using the same version.

```julia
julia> using GR 

julia> version()
"0.48.0.post37"

julia> using Plots 

julia> Plots.GR.version()
"0.48.0.post37"

```

By the way I am using Plots v0.29.8

```julia
pkg> status "Plots"
Status `~/.julia/environments/dev-env/Project.toml`
  [91a5bcdd] Plots v0.29.8

```

---

<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: [March 28, 2020, 7:46pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/10 "2020-03-28T19:46:10Z")

</div>

Right now I’m a little at a loss. I would have to try to reproduce it somewhere, but I don’t have a comparable system at the moment. This is about Debian with a current VSCode? Exact version information would be helpful - with that I would try to recreate it on Monday.

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [May 6, 2020, 3:47pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/11 "2020-05-06T15:47:37Z")

</div>

Setting `ENV["GKSwstype"] = "100"` (in `startup.jl` to avoid setting all the time Julia is launched) solved the problem. Now nothing wrong with using `GR` as a backed of Plots in VSCode.

---

<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 21, 2021, 8:22am UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/12 "2021-05-21T08:22:29Z")

</div>

Thanks for the immediate response

 ![error](https://global.discourse-cdn.com/julialang/original/3X/e/3/e3831c826ee12a2d733dbf611cb641d8e1b130b8.png)

If you mean I should copy and paste this code ENV[“GKSwstype”] = “100” on Julia and press Enter. I did but still there is no plot.  
I am a newbie in Julia and I am not familiar with Julia. I only use Matlab and a little Python  
I don’t know why the shape of Julia is not complete and doesn’t have any color. maybe it has something to do with this problem???  
I installed the same atoms and Julia on my friend’s loptop which has windows 7 . it works and I did my project but I want it on my loptop.

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [May 21, 2021, 12:06pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/13 "2021-05-21T12:06:56Z")

</div>

> [@sajad\_ghassemi](#):
>
> I don’t know why the shape of Julia is not complete and doesn’t have any color. maybe it has something to do with this problem???

No, it has nothing to do with it.

> [@sajad\_ghassemi](#):
>
> If you mean I should copy and paste this code ENV[“GKSwstype”] = “100” on Julia and press Enter. I did but still there is no plot.

You can copy and paste `ENV[“GKSwstype”] = “100”` in the repl. However, once the repl is relaunched, you must repeat this again. To avoid setting this all the time the repl is launched, you can write this setting in your `.startup.jl` file.

This file should be located somewhere like `C:\Users\USERNAME\.julia\config\startup.jl`. So, you need to open and add the line `ENV[“GKSwstype”] = “100”` in the `startup.jl` file. If the file is not present, you should create it on your own.

To check if the file exits in your system, you can follow these steps.

```julia

using Pkg

depotpath = first(Pkg.depots()) # The output should something like `C:\Users\USERNAME\.julia`

configdir = joinpath(depotpath, "config")

isdir(configdir) || mkdir(config) # Check if config directory exists, if not construct it.

configfile = joinpath(configdir, "startup.jl")

isfile(configfile) || touch(configfile) # Check if startup.jl exits, if not construct it

```

To open `startup.jl` file in a text editor like `atom` and edit it manually, you can specify the editor

```julia
ENV["EDITOR"] = "atom" # Choose whichever editor your prefer. Here I choose atom from your screenshot
edit(configfile)

```

At this point, the file should be opened in the atom editor and you can edit it. Just add the line `ENV[“GKSwstype”] = “100”` in the file, save and close. Now you are all done. To check, close and relaunch the repl, and type

```julia
ENV[“GKSwstype”]

```

The output must be `"100"`.

---

<div class="post-metadata">

### Author: ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)
#### Post date: [May 21, 2021, 12:26pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/14 "2021-05-21T12:26:53Z")

</div>

And I suggest [julia extension for vscode](https://www.julia-vscode.org/) instead of [julia extension for Atom](https://junolab.org/) (called Juno). See the warning in the documentation of Juno extension.

> We have decided to join forces with the Julia extension for VSCode. As such, this Atom-based plugin is effectively in “maintenance-only mode” and we expect to only work on bug fixes in the future.

---

<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 21, 2021, 12:40pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/15 "2021-05-21T12:40:31Z")

</div>

> [@zekeriya.sari](#):
>
> ENV[“GKSwstype”] = “100”

Thanks for the detaiIed explanation. I did step by step as you mentioned but when I saved the ENV[“GKSwstype”] = “100” in startup.jl  
the EPRL doesn’t work.

 ![error](https://global.discourse-cdn.com/julialang/original/3X/5/a/5afd7377a54cfb584f182e5922bec69ef43f0653.png)

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [May 21, 2021, 12:41pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/16 "2021-05-21T12:41:54Z")

</div>

Looks like you ended up with weird Unicode quotation marks there instead of `"`.

---

<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 21, 2021, 12:49pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/17 "2021-05-21T12:49:25Z")

</div>

when I delete that code (ENV[“GKSwstype”] = “100”) from startup.jl and save it .  
The EPRL works.  
I don’t know why the plotly work but plot doesn’t work. I think it is better to use another IDE instead of Atoms

---

<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: [May 21, 2021, 6:49pm UTC](https://discourse.julialang.org/t/gks-error-when-plotting-in-vs-code/36618/18 "2021-05-21T18:49:00Z")

</div>

There is no reason to change `GKS_WSTYPE` in Atom. GR (or Plots) will recognize that Atom is running and produce plots in the Plots pane. The only thing you might have to change is the color theme (`usecolorscheme(2)` for dark mode):

 ![Screen Shot 2021-05-21 at 20.48.30](https://global.discourse-cdn.com/julialang/original/3X/d/b/db8f55414137ec95255f2b8b1455f2979b0fa34c.jpeg)
