show matplotlib plots directly in your sixel-enabled terminal
Project description
matplotlib-backend-sixel
This python module allows you to use your sixel-enabled terminal to show inline plots generated by python's matplotlib.
The module is a modified version of the kitty backend and is also based on this earlier sixel backend.
You will need a terminal that has support for the SIXEL graphics format and imagemagick installed.
To install either run
$ pip install --user matplotlib-backend-sixel
or clone this repo and run
$cd matplotlib-backend-sixel && pip install .
Configure matplotlib to use the module by either setting the
environment variable MPLBACKEND
to module://matplotlib-backend-sixel
or by initializing matplotlib as follows.
import matplotlib
matplotlib.use('module://matplotlib-backend-sixel')
import matplotlib.pyplot as plt
If you've installed this module correctly, you can now use the following sample code to draw a plot in your terminal.
$ ipython
In [1]: import matplotlib
...: matplotlib.use('module://matplotlib-backend-sixel')
...: import numpy as np
...: import matplotlib.pyplot as plt
...: plt.style.use("dark_background")
...: t = np.linspace(0,5,200)
...: plt.fill_between(t,np.sin(t),np.cos(2*t),alpha=0.5)
...: plt.fill_between(t,np.cos(t),np.sin(2*t),alpha=0.5)
...: plt.show()
<plot is shown>
If you set your matplotlib to interactive mode via
matplotlib.pyplot.ion()
or by running python as
python -i
, non-empty figures are drawn on construction
where possible. This allows you to use pandas' plot()
calls directly, without calling plt.show()
, and still
enables you to manually construct and plt.show()
.
If your matplotlib is in non-interactive mode,
you can construct your figures as usual, and then call
plt.show()
to render them to your terminal. This
works from both a repl and when running scripts.
Internally, this backend is somewhat based on matplotlib's
IPython support: it's a hybrid of image and GUI backend types.
It works by using matplotlib's Agg
backend to render the
plot, and then calls imagemagick
to convert to sixel format
and then cat the image to your terminal. This means that plotting works as
expected, but the image drawn to your terminal isn't
interactive and animations aren't supported.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file matplotlib-backend-sixel-0.1.0.tar.gz
.
File metadata
- Download URL: matplotlib-backend-sixel-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b4b93dd2abaf75187815f925e32011259dfbf36b27da609d542b51eadb59af |
|
MD5 | 4a9c7e74077af787abb4139d5a9b798f |
|
BLAKE2b-256 | 119718b74df33356a418ae73acbe39c3f42684bd15bdf908146dbc67d3182367 |
File details
Details for the file matplotlib_backend_sixel-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: matplotlib_backend_sixel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 049f2a8174df7e820c9cdc4d36f41c1ebbea6b38e89e0013662d9662271c131f |
|
MD5 | 814ba17a200bb628f89af31ad8e073b2 |
|
BLAKE2b-256 | a65f6e4c192d812739e030957ea933fa436494d72707dd67c3a5edb7fae8f9d1 |