Small pure-Python ASCII plotting utility for rendering numeric sequences and (x, y) data directly in a terminal.
The project is a Python 3 port of the original aplotter.py by Imri Goldberg. It currently consists of a single module, aplotter.py.
- Plot a single numeric sequence against its index
- Plot explicit
xandysequences - Draw approximate slopes with ASCII line characters
- Optional axes and axis-bound labels
- No third-party dependencies
- Python 3
Install in editable mode from the repo root:
pip install -e .That exposes an aplotter command via the console script declared in pyproject.toml.
Render a sequence against its index:
from aplotter import Plotter
values = [0, 1, 4, 9, 16, 25]
plotter = Plotter()
print(plotter.plot_single(values))Render explicit x and y values:
from aplotter import Plotter
x = list(range(-5, 6))
y = [n * n for n in x]
plotter = Plotter(x_size=40, y_size=12)
print(plotter.plot_double(x, y))Use the convenience function:
import aplotter
aplotter.plot(
range(-5, 6),
[n * n for n in range(-5, 6)],
x_size=40,
y_size=12,
)Use the CLI with positional y values:
aplotter 0 1 4 9 16 25 --x-size 40 --y-size 12Use the CLI with explicit x and y values:
aplotter --x -5 -4 -3 -2 -1 0 1 2 3 4 5 --y-values 25 16 9 4 1 0 1 4 9 16 25Plotter accepts these keyword arguments:
x_size: plot width in characters, default80y_size: plot height in characters, default20draw_axes: draw axes when0is inside the visible range, defaultTrueplot_labels: draw min/max labels near the axes, defaultTrueplot_slope: connect adjacent points with ASCII slope characters, defaultTruedot: base character for plotted points, default*x_margin: horizontal padding ratio around the data, default0.05y_margin: vertical padding ratio around the data, default0.1newline: line separator used when returning the rendered string, default"\n"
plot_double() also accepts optional bounds:
min_xmax_xmin_ymax_y
Plotter.plot_single(seq, min_x=None, max_x=None, min_y=None, max_y=None)
- Treats
seqasyvalues and usesrange(len(seq))forx
Plotter.plot_double(x_seq, y_seq, min_x=None, max_x=None, min_y=None, max_y=None)
- Plots matching
xandysequences - Raises
ValueErrorif the sequences are empty or have different lengths
plot(*args, **flags)
- Convenience wrapper that prints directly to stdout
- Supports either
plot(y_seq, ...)orplot(x_seq, y_seq, ...)
main(argv=None)
- CLI entry point used by the
aplotterconsole script - Supports either positional
yvalues or--xwith--y-values
python -m unittest -v- This is a terminal-oriented plotting helper, not a replacement for graphical plotting libraries.
- Multi-series plotting is not implemented.
- The module is currently distributed as a single file rather than a packaged library.