Using GR on remote systems
If you are in the fortunate position to be able to use iTerm2 under macOS and if you are looking for a simple solution to visualize data on a remote system, e.g. an HPC system, then this blog post might be helpful.
It is often not intended (or desired) to use interactive plotting software on HPC systems, which are actually designed for computing. With a private Julia installation, however, you can remedy the situation without much installation effort.
Installation
The Julia distribution can be downloaded directly from julialang.org and unpacked in your home directory. After that you can use Julia instantaneously from the command line:
${HOME}/julia-1.6.3/bin/julia
For easier use, you can either adjust your PATH variable accordingly, define an alias, or use a small startup script. In this post, I would like to recommend the latter:
#!/bin/sh
juliadir=${HOME}/julia-1.6.3
if [ "$1" = "-o" ]
then
shift
if [ "`echo $1 | grep '\.'`" != "" ]
then
type=`echo $1 | awk -F. '{print $NF}'`
export GKS_FILEPATH="$1"
export GKS_WSTYPE="$type"
else
export GKS_WSTYPE="$1"
fi
shift
fi
exec ${juliadir}/bin/julia "$@"
The advantage of this script is that you can specify the output device when starting Julia:
julia -o iterm
But first we need to install the necessary Julia packages, in our case GR and LaTeXStrings:
] add GR
] add LaTeXStrings
A simple example
Now, that you have started Julia as described, you can display plots directly in the iTerm2 terminal window.
using GR
using LaTeXStrings
𝒩(μ, σ) = 1 / (σ * √(2π)) * exp.(-0.5 * ((x .- μ) / σ) .^ 2);
x = LinRange(-5, 5, 500);
y = hcat(𝒩(0, √0.2), 𝒩(0, √1), 𝒩(0, √5), 𝒩(-2, √0.5));
plot(x, y, xlabel=L"\mathcal{X}", ylabel=L"\mathcal{N}(\mu,\,\sigma^{2})", title=L"\frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{1}{2} \left({\frac{x-\mu}{\sigma}}\right)^2}", labels=(L"\mu=0, \sigma^2=0.2", L"\mu=0, \sigma^2=1", L"\mu=0, \sigma^2=5", L"\mu={-2}, \sigma^2=0.5"), xlim=(-5.2, 5.2), ylim=(-0.05, 1.05), linewidth=3)
The result is a graphic embedded in the terminal dialog. Rendering of the graphic is done at the server side - internally a PDF document is generated, which is then displayed by the iTerm2 terminal emulator.
Even for plots with a lot of points or markers, the plot is displayed efficiently and quickly.
Conclusion
In the way shown here, even large amounts of data can be visualized, as this is often the use case on HPC systems. The data does not need to be transferred and the communication requirement is limited to the transfer of a PDF document file.
Of course, the plot could also be displayed as usual with the default output device (GKS QtTerm
). But this requires a local X server, e.g. XQuartz and the forwarding of the X11 protocol, which in turn is not always given or useful, e.g. when working over a slow connection.