Gks Error When Plotting in VS Code

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> 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

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

libx11-xcb1 is already installed in the system.

$ 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

$ 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

Can you reproduce the behaviour with plain GR?

using GR
plot(randn(10))

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

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

VSCode should now create an inline plot, right?

1 Like

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> using GR 

julia> inline("svg")
"svg"

julia> plot(rand(10))

julia> inline("png")
"png"

julia> plot(rand(10))


and this is the case when I plot in bash terminal.

$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

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

using GR
usecolorscheme(2)
...

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

Plots.GR.usecolorscheme(2)

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

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

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

using GR
version()

should be the same as

using Plots
Plots.GR.version()

I am using the same version.

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

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

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.

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.

1 Like

Thanks for the immediate response

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.

No, it has nothing to do with it.

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.


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

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

ENV[“GKSwstype”]

The output must be "100".

1 Like

And I suggest julia extension for vscode instead of julia extension for Atom (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.

3 Likes

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.

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

1 Like

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

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):

3 Likes