SIXEL graphics for Sage?

227 views
Skip to first unread message

Erik Bray

unread,
Aug 30, 2017, 9:51:58 AM8/30/17
to sage-devel
Hi,

Has anyone here tried playing around with the SIXEL graphics format
for Sage plots before? SIXEL [1] is a graphics format that was
supported by VT300 terminals for displaying images in the terminal,
and many terminal emulators support it. For example, gnuplot has long
been able to display plots in SIXEL format (see attached screenshot),
and I've used in the past for displaying images in the terminal (there
are programs that can convert existing images to SIXEL and cat them).

I just wonder if anyone's found a workaround for this to work in Sage,
rather than have plots pop up in a separate image viewer.

ISTM if nothing else, this could be done in a hackish way by taking
images output by Sage, pass them through a SIXEL converter, and then
print the SIXEL data. I haven't tried fully integrating this, but
simply print()ing a SIXEL image from Python works from the Sage REPL,
at least on my terminal.

Surely I'm not the only one who's tried this?

Erik

[1] https://en.wikipedia.org/wiki/Sixel
2017-08-30.png

Samuel Lelievre

unread,
Jan 31, 2018, 10:02:19 AM1/31/18
to sage-devel
[Warning: this is a reply to a 5-month-old post.]

Wed 2017-08-30 13:51:58 UTC, Erik Bray:
Sorry I didn't reply when you wrote this, the last days of August
and first days of September I was busy moving to Mexico...

I was amazed by your post and screenshot, never having thought
such integration of graphics in the terminal was possible. Having
this for the Sage REPL would be wonderful. Please open a ticket
and/or write instructions in a blog post or a wiki page.

Samuel

Erik Bray

unread,
Jan 31, 2018, 10:45:05 AM1/31/18
to sage-devel
Heh, I sort of lost interest when I posted this and nobody else seemed
interested.

But I agree it would be very nice to have. There's a very nice Python
library that implements this (called, naturally, PySixel
https://github.com/saitoha/PySixel) and I it would be easy to add as a
possible output formatter for 2D graphics in Sage.

The one downside to this is that not all terminals support this
(though many common ones do), and there's no easy way from within Sage
to detect whether the user's terminal would support it.
It might be possible with some obscure terminal control codes to
detect but I'm not sure. The best way is to just enable it and try
it, and if it works--great--enable it by default as a setting or
something.

There also seem to be some other terminal-specific proprietary codes
for image rasterization in terminals, but Sixel is a documented DEC
standard and seems to be in a lot of terminals (including xterm,
mintty on Windows, and I'm pretty sure the terminal on OSX).

Best,
E

Frédéric Chapoton

unread,
Oct 23, 2018, 2:58:27 PM10/23/18
to sage-devel
I have created a ticket at https://trac.sagemath.org/ticket/26544

Sébastien Labbé

unread,
Oct 24, 2018, 7:00:15 AM10/24/18
to sage-devel
This seems great! It seems something that should be incorporated in ipython as an option so that Sage could just use it.

Sébastien Labbé

unread,
Oct 24, 2018, 7:02:12 AM10/24/18
to sage-devel


On Wednesday, October 24, 2018 at 1:00:15 PM UTC+2, Sébastien Labbé wrote:
This seems great! It seems something that should be incorporated in ipython as an option so that Sage could just use it.

Erik Bray

unread,
Oct 28, 2018, 8:05:59 AM10/28/18
to sage-...@googlegroups.com
Glad to see this getting attention again. It's still something that I
think would be really cool.

The biggest problem I had,last time I played around with this, is I
could not find a reliable way to *test* (without displaying anything
to the user) whether the user's terminal emulator explicitly supports
SIXEL mode or not. It seems the best one can do is simply maintain
(as others have already done) a list of terminals that support this,
and have an easily discoverable way to manually enable it in Sage.

But if it works it works--it would be really cool for displaying plots
and rendered latex in the console.
Reply all
Reply to author
Forward
0 new messages