Plots in the terminal (with sixel)

#1

I just came across “sixel” which allows to show graphics in the terminal (while reading this https://github.com/csdvrx/sixel-gnuplot )

Unfortunately, gnome-terminal does not support this (https://bugzilla.gnome.org/show_bug.cgi?id=729204), but xterm (run as xterm -ti vt340) does.

In fact it does not take much to use this with julia and PyPlot (or any other plotting package), just the convert tool from ImageMagic.

I started Julia with unset DISPLAY (on Linux)

using PyPlot
plt.style.use("dark_background")
function show()
   fname = tempname() * ".png";
   savefig(fname)
   run(`convert $fname -geometry 800x480  sixel:-`)
   return nothing
end
x = 1:0.1:10;
pcolor(sin.(x) * sin.(x)');
show()

Off-topic, but also useful is lsix: “ls” for images (https://github.com/hackerb9/lsix)

5 Likes
#2

You could also try the unregistered https://github.com/tshort/SixelTerm.jl. It uses ImageMagick.

2 Likes
#3

SixelTerm.jl is really nice! Thanks for sharing! It is quite impressive what you can do with 30 lines of code in SixelTerm.jl.

1 Like
#4

GR has builtin sixel support:

using GR
inline("iterm")
contourf(peaks())

Could also be integrated into Plots gr() backend - just let me know …

7 Likes
#5

It could also be useful to overload the display function to make a plot for long vector and a heatmap for large matrices. I think I will use the feature at lot more!

ENV["GKSwstype"] = "nul"    # needed for the GR backend on headless servers
using Plots
using SixelTerm
using NCDatasets

function Base.display(x::Matrix{T}) where T <: Union{Number,Union{Missing,Number}}
    if length(x) < 300
        invoke(display, Tuple{AbstractMatrix}, x)
    else
        display(heatmap(coalesce.(x,NaN)', color=:lightrainbow))
    end
end


ds = Dataset("/home/abarth/Data/DivaData/Global/gebco_30sec_16.nc");
bathymetry = ds["bat"][:,:] # returns a Array{Union{Missing, Float32},2}

#6

… no need to overload display in GR: :grinning:

4 Likes
#7

Not in the REPL but I still prefer

using GMT
grdimage("@earth_relief_05m.grd", proj=:Winkel, fmt=:png, show=true)

#8

But if I see that correctly, this means, that GR.jl can only plot using terminals that are hard coded in GR.jl, right`

#9

I ran into some pages in Japanese when looking for the details of the sixel generation algorithm so I cannot judge how complex it is, but I am wondering if it would make sense to have a native Julia implementation. It would have obvious advantages for all packages using this functionality, and could also serve as a nice reference.

#10

GR.jl is only a wrapper for the GR framework. Any software that uses GR.jl can produce sixel graphics. It’s just about converting an internally rendered image to sixels …

Thus, it can be used from Julia, Python C, or whatever.

#11

The latest release of Gaston also supports sixel:

I had had experimental support for a while, but this thread motivated me to finish it up. Also, since gnuplot has native sixel support, no external libraries or converters are needed.

2 Likes