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?

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.