6 ms·
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 vi
by db48x 4y ago
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)"
- msla 4y agoAlso: https://github.com/saitoha/libsixel 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 https://github.com/saitoha/FFmpeg-SIXEL GUI apps: https://github.com/saitoha/SDL1.2-SIXEL https://github.com/saitoha/SDL1.2-SIXEL and more, linked from the libsixel repository.
- junon 4y agoSixel 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.
- smasher164 4y agoYeah, in an effort to spur adoption, I built (shameless plug) https://www.arewesixelyet.com/ https://www.arewesixelyet.com/. What’s interesting is that if VTE gets support, a lot of other terminals will, since they depend on it.
- kps 4y agomlterm supports sixels — https://github.com/arakiken/mlterm https://github.com/arakiken/mlterm
- smasher164 4y agoThanks! Added it: https://github.com/smasher164/arewesixelyet/commit/4e8f68e98ca https://github.com/smasher164/arewesixelyet/commit/4e8f68e98....
- junon 4y agoOoh thanks! I love this.
- dolmen 4y agoSee https://github.com/dolmen-go/kittyimg https://github.com/dolmen-go/kittyimg
- dgacmu 4y agoThis 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.
- db48x 4y agoIt’s one of the lesser–known superpowers :)
- wpietri 4y agoIs 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.
- db48x 4y agoI 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.
- cb321 4y agoWithin 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`.
- db48x 4y agoNo need for any of that; gnuplot can just read from the pipe directly: `seq 1 10 | gnuplot -e "plot '<&2'"`
- cb321 4y agoNice! 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 https://news.ycombinator.com/item?id=34365290
- Aardwolf 4y agoThis 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.
- TomJansen 4y agoKonsole now supports many different image rendering protocols: sixel, iTerm2 and Kitty image protocols. See https://invent.kde.org/utilities/konsole/-/merge_requests/594 https://invent.kde.org/utilities/konsole/-/merge_requests/59...
- db48x 4y agoMagic :) 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.
- __alexs 4y agoxterm even has a tektronix mode which can render vector graphics directly in the terminal. [1] https://www.dim13.org/teapot https://www.dim13.org/teapot [2] https://jirkasnotes.wordpress.com/2019/07/17/xterm-does-graphics-sort-of/ https://jirkasnotes.wordpress.com/2019/07/17/xterm-does-grap...
- db48x 4y agoYes, but only in monochrome, and in a separate window.
- cb321 4y agohttps://st.suckless.org/ 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 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/ https://st.suckless.org/patches/
- rjzzleep 4y agoThere’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 https://github.com/microo8/alacritty-sixel [2] https://sw.kovidgoyal.net/kitty/graphics-protocol/ https://sw.kovidgoyal.net/kitty/graphics-protocol/
- cb321 4y agoYeah. 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 https://news.ycombinator.com/item?id=34366758
- lajosbacs 4y agoDidn'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`
- quijoteuniv 4y agoExcellent! Often the results from reading about “new” tools in HN is that i find out about well established tools i should check before :)
- synergy20 4y agosomeone 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?
- enriquto 4y ago> 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://invisible-island.net/xterm/xterm.log.html https://gitlab.gnome.org/GNOME/vte/-/commits/master 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/master https://gitlab.gnome.org/GNOME/gnome-terminal/-/commits/mast...
- synergy20 4y agolast time I checked xterm can not do utf8 yet
- enriquto 4y agoIt 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/ https://www.invisible-island.net/xterm/bad-utf8/
- synergy20 4y agoyes thanks,utf8 indeed works
- db48x 4y ago
- deleted 4y ago[deleted]
- jvanderbot 4y agoMy friend wrote a gnuplot wrapper that is a bit cleaner to use called 'feedgnuplot' https://github.com/dkogan/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.