Python plotting for the command line
Project description
termplotlib
termplotlib is a Python library for all your terminal plotting needs. It aims to work like matplotlib.
Line plots
For line plots, termplotlib relies on gnuplot. With that installed, the code
import termplotlib as tpl
import numpy as np
x = np.linspace(0, 2 * np.pi, 10)
y = np.sin(x)
fig = tpl.figure()
fig.plot(x, y, label="data", width=50, height=15)
fig.show()
produces
1 +---------------------------------------+
0.8 | ** ** |
0.6 | * ** data ******* |
0.4 | ** |
0.2 |* ** |
0 | ** |
| * |
-0.2 | ** ** |
-0.4 | ** * |
-0.6 | ** |
-0.8 | **** ** |
-1 +---------------------------------------+
0 1 2 3 4 5 6 7
Horizontal histograms
import termplotlib as tpl
import numpy as np
rng = np.random.default_rng(123)
sample = rng.standard_normal(size=1000)
counts, bin_edges = np.histogram(sample)
fig = tpl.figure()
fig.hist(counts, bin_edges, orientation="horizontal", force_ascii=False)
fig.show()
produces
Horizontal bar charts are covered as well. This
import termplotlib as tpl
fig = tpl.figure()
fig.barh([3, 10, 5, 2], ["Cats", "Dogs", "Cows", "Geese"], force_ascii=True)
fig.show()
produces
Cats [ 3] ************
Dogs [10] ****************************************
Cows [ 5] ********************
Geese [ 2] ********
Vertical histograms
import termplotlib as tpl
import numpy as np
rng = np.random.default_rng(123)
sample = rng.standard_normal(size=1000)
counts, bin_edges = np.histogram(sample, bins=40)
fig = tpl.figure()
fig.hist(counts, bin_edges, grid=[15, 25], force_ascii=False)
fig.show()
produces
Tables
Support for tables has moved over to termtables.
Installation
termplotlib is available from the Python Package Index, so simply do
pip install termplotlib
to install.
Testing
To run the termplotlib unit tests, check out this repository and type
pytest
Similar projects
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
termplotlib-0.3.9.tar.gz
(24.5 kB
view details)
Built Distribution
File details
Details for the file termplotlib-0.3.9.tar.gz
.
File metadata
- Download URL: termplotlib-0.3.9.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c04cbd67ac61753eac9162a99cbe87c379d4c5daf720af1df55f4423c094203e |
|
MD5 | 8f8858a70743582d2af1cc8bcb6c20c8 |
|
BLAKE2b-256 | b4608a74d2503dd64975402c7b8d00f6e201e8cbba5348282433fa5fb8d41b67 |
File details
Details for the file termplotlib-0.3.9-py3-none-any.whl
.
File metadata
- Download URL: termplotlib-0.3.9-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 827bec59e0de24dfe265b9d9a4adc4df8335aa98f49c1122bd53ced9b72c5206 |
|
MD5 | 9d224fee7b788b1b41190bf1939ef861 |
|
BLAKE2b-256 | 69d0ea24907a6d1e3c5e40ff5b58920552c3e1e4e73181a8583d5bd9d5217305 |