Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you really want to draw plots on the terminal, run `xterm -ti 340` and then use gnuplot, like this:

    gnuplot -e "set terminal sixelgd;set hidden3d;set view 60, 30, 1, 1.1;set samples 50, 50;set isosamples 52, 52;set contour base;set cntrparam order 8;set cntrparam bspline;splot [-12:12.01] [-12:12.01] sin(sqrt(x**2+y**2)) / sqrt(x**2+y**2)"


Also:

https://github.com/saitoha/libsixel

contains img2sixel, which lets you dump images to the terminal. It can also do animated GIFs.

Video:

https://github.com/saitoha/FFmpeg-SIXEL

GUI apps:

https://github.com/saitoha/SDL1.2-SIXEL

and more, linked from the libsixel repository.


Sixel is, woefully, not very well supported by terminal emulators :/ I really wish it were.

There's also the Kitty graphics API but I've never actually seen it work on any machines I've used Kitty, Wezterm, etc. that supposedly support it.


Yeah, in an effort to spur adoption, I built (shameless plug) https://www.arewesixelyet.com/. What’s interesting is that if VTE gets support, a lot of other terminals will, since they depend on it.


mlterm supports sixels — https://github.com/arakiken/mlterm



Ooh thanks! I love this.



This is astoundingly great - thank you for linking!

(The expected use case - generating quick plots on a remote machine; I usually just scp them back, but with this, and the new-to-me matplotlib integration, i can just have them show up in the terminal without having to launch a notebook or fight with X). Well supported by iterm2 on mac as the terminal side.


It’s one of the lesser–known superpowers :)


xterm even has a tektronix mode which can render vector graphics directly in the terminal.

[1] https://www.dim13.org/teapot [2] https://jirkasnotes.wordpress.com/2019/07/17/xterm-does-grap...


Yes, but only in monochrome, and in a separate window.


https://st.suckless.org/ used to have a circa st-0.8 fork that supported full color sixel graphics, but it seems that specific patch is not in the official list anymore. [1] I think the work moved to https://github.com/jhhuh.

You can even compose the gnuplots with the scrollback patch to scroll back in your gnuplots. I use this all the time. In fact, I just have GNUTERM="sixelgd enhanced linewidth 3 fontscale 2 size 1600,900 truecolor" in my environment variables.

Combined with shell history (or gnuplot history) this makes for a rudimentary "notebook"-like interface, but with a log instead of a file to record state.

[1] https://st.suckless.org/patches/


There’s an alacritty fork with sixel support[1], albeit without vector support.

There’s also kitty that has some improvements over sixel[2]

[1] https://github.com/microo8/alacritty-sixel

[2] https://sw.kovidgoyal.net/kitty/graphics-protocol/


Yeah. Good points!

You could also use the techniques of [1] but use `set term png` and `set output "/tmp/pl.png"` instead and then auto-launch any image viewer on "/tmp/pl.png" instead of relying on terminal graphics at all.

[1] https://news.ycombinator.com/item?id=34366758


That would completely defeat the point! :)


Lol :)



Is gnuplot better for the use cases demonstrated on the page here?

I've always avoided gnuplot because it has looked pretty hard to get anything useful out of. But uplot looks much more approachable. Just piping some data to "uplot hist --nbins 20" is something I'll remember.


You just need a better frontend. A distribution of file sizes < 100kB in my home directory:

  ls -l                            \
  | awk '$5 < 100000 {print $5}'   \
  | feedgnuplot                    \
      --histo 0                    \
      --binwidth 5000              \
      --xlabel 'File size (bytes)' \
      --ylabel Frequency           \
      --terminal 'dumb 120 40'     \
      --unset grid

     45 +-----------------------------------------------------------------------------------------------------------+
        |  *      *   +            +             +            +             +            +             +            |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     40 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     35 |***      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     30 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     25 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     20 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     15 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     10 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
      5 |-+*      ********                                                                                        +-|
        |  *      *      *                                              ********                                    |
        |  *      *      ********     **********************     ********      *                                    |
        |  *      *   +  *      *  +  *      *   +  *      *******      *   +  *         +             +  ********  |
      0 +-----------------------------------------------------------------------------------------------------------+
        0           10000        20000         30000        40000         50000        60000         70000        80000
                                                      File size (bytes)
Usually you want graphical output, but it does fine in ascii


Oh hey Dima.

Feedgnuplot is really slick.

https://github.com/dkogan/feedgnuplot

It's in the debian repos too.


I don’t actually get much chance to use gnuplot, but it can plot data from a pipe. The syntax is a bit more involved as I recall.


Within the gnuplot shell you use `<` at the start of a "filename" like

    gnuplot> plot '<pipeline'
It just uses system(3) for "pipeline". So, technically you could have a whole script in there with maybe tricky gnuplot-quoting/escaping of shell stuff.

You do have 2 different history logs this way - the shell one and the plot one while the uplot way is integrated.

If you really want integrated, you could drive gnuplot with temp files, though each shell command-line would probably have to pass a lot of controls. E.g.,

    #!/bin/sh
    cat > /tmp/dat          # should use mktemp -d
    cat > /tmp/p.gpi <<-EOF
    plot '/tmp/dat' $*
    EOF
    gnuplot /tmp/p.gpi
and then

    $ seq 1 10 | gpl with lines
It is an exercise for the reader (well, it has probably been done N times...) to harden the temp paths, clean up afterward, generalize to source user/maybe per-directory `foo.gpi` setup and so on.

In the unlikely event temp space is actually any sort of issue then you might be able to use mkfifo (I've never tried) or else generate a .gpi script that uses the plot '<string' syntax escaping `string`.


No need for any of that; gnuplot can just read from the pipe directly: `seq 1 10 | gnuplot -e "plot '<&2'"`


Nice! Added in 2008, if anyone is curious. (EDIT: and in db48x's comment already[1]) Also, I had to put in a `cat` to make it work:

    seq 1 10 | gnuplot -e "plot '<cat' with lines"
[1] https://news.ycombinator.com/item?id=34365290


Oh, that goes to show you how little I use it. I read the documentation and merely assumed that it would work for stdin, but gnuplot exits with an error in that case. This will work, but it’s pretty funky:

    gnuplot -e "set terminal sixelgd;plot '<&3' with lines" 3< <(seq 1 10)
Good luck remembering that!


No need of cat. You can use filename "-" to mean standard input:

    seq 1 10 | gnuplot -e 'plot "-"'


This worked directly in Konsole for me without "xterm -ti 340" and it renders a high res image, which surprised me: I have used low-res images in the terminal using block characters and 24-bit colors before, but never seen this high res

How does it do this?

One weird thing seems to be that it doesn't support zooming in/out the same way the regular text does.


Konsole now supports many different image rendering protocols: sixel, iTerm2 and Kitty image protocols. See https://invent.kde.org/utilities/konsole/-/merge_requests/59...


Magic :)

No, for the VT340 they devised a set of escape sequences for encoding bitmaps called Sixels; each character encodes a vertical stripe of six pixels. They used it both for displaying graphics and printing. They also did a vector graphics system called ReGIS a few years earlier.


Didn't know it can do that (in iterm2 works nicely).

My favourite use of gnuplot, over ssh, is to plot ascii, just like the presented tool does. Just use

  set terminal dumb size `tput cols` `tput lines`


Excellent! Often the results from reading about “new” tools in HN is that i find out about well established tools i should check before :)


someone please enlighten me, why can xterm do this cool drawing while the modern gnome-terminal can not, I tested the GPU oriented kitty that can display images in terminal, but it could not run gnuplot as xterm. what're missing?


XTerm implements an old bitmap protocol invented in the 80s. The author of Kitty rightly points out that it’s inefficient, limited to one color per column of 6 pixels (if you want a second color you can go back to the start of the line and print over). Rather than implement support for the Sixel protocol, the author of Kitty choose to implement something modern. It’s actually rather nice; the program can print out a filename for Kitty to load, or even point to a shared memory buffer. Those are very efficient options, provided your program is running on your local machine.

Meanwhile Gnuplot supports a wide variety of “terminals”, many of which are just outputs to files of various types, some of which are GUIs, others of which are for actual terminals, like “dumb” (ordinary printable characters), “tek40” and “xterm” which use a protocol invented for Tektronix terminals, “sixelgd” which uses the sixel protocol from the VT340, half a dozen types of printers, etc.

But nobody has added one for the Kitty protocol, so it doesn’t work there. The downsides of inventing something new I suppose; the existing software doesn’t automatically support it, someone has to go around and add that support.



> what're missing?

Nothing. Xterm is awesome!

And even if xterm is an older program, it seems to be just as actively developed as gnome-terminal. See the changelogs for each:

https://invisible-island.net/xterm/xterm.log.html

https://gitlab.gnome.org/GNOME/vte/-/commits/master

The second link points to libvte, which is the terminal engine behind gnome-terminal where the actual terminalling happens. The changes to gnome-terminal itself are mostly translations and uninteresting desktop stuff:

https://gitlab.gnome.org/GNOME/gnome-terminal/-/commits/mast...


last time I checked xterm can not do utf8 yet


It certainly can. Since more than 20 years ago! I remember that in 2003, as a "little kid", I changed my configuration from latin-15 to utf8 and it was already supported.

You can read here an explanation of how xterm handled ill-formed utf8 characters in 1999: https://www.invisible-island.net/xterm/bad-utf8/


yes thanks,utf8 indeed works


My friend wrote a gnuplot wrapper that is a bit cleaner to use called 'feedgnuplot'

https://github.com/dkogan/feedgnuplot

It's in the debian repos so you can pull it if you're in a debian derivative too, like Ubuntu.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: