termplotlib

raw JSON →
0.3.9 verified Mon Apr 27 auth: no python

Library for plotting in the terminal using Unicode characters. Current version 0.3.9, released irregularly. Supports line plots, horizontal and vertical bar charts. Requires Python >=3.7.

pip install termplotlib
error AttributeError: module 'termplotlib' has no attribute 'tpl'
cause Importing alias 'tpl' as a submodule instead of using import termplotlib as tpl.
fix
Use 'import termplotlib as tpl' then 'tpl.figure()'.
error ValueError: x and y must have same first dimension
cause Input arrays for line or bar plots have different lengths.
fix
Ensure x and y (or left and right for barh) have the same length.
gotcha The library does not support interactive plots or windowed output. It only prints to terminal.
fix Use print(fig.get_string()) or fig.show() to render to stdout.
gotcha Data must be provided as lists or numpy arrays. Other iterables may not work correctly.
fix Convert to list or numpy array before plotting.
gotcha Bar charts require exactly two arrays of equal length for horizontal bars.
fix Check that your input arrays have the same size.

Basic line plot using numpy arrays.

import termplotlib as tpl
import numpy as np

x = np.linspace(0, 2*np.pi, 20)
y = np.sin(x)

fig = tpl.figure()
fig.plot(x, y, label='sine')
fig.show()