Asciichartpy
Asciichartpy is a lightweight Python library for drawing nice-looking console ASCII line charts directly in your terminal. It offers simple, dependency-free charting for command-line applications and scripts. The current version is 1.5.25, with releases occurring periodically to address minor issues and improvements.
Common errors
-
TypeError: unsupported operand type(s) for +: 'int' and 'str'
cause Attempting to plot a series containing non-numeric data (e.g., strings mixed with numbers). `asciichartpy` expects all series values to be integers or floats.fixCleanse your data to ensure all values in the series are convertible to numbers. Example: `data = [float(x) for x in raw_data if x.isdigit()]`. -
AttributeError: module 'asciichartpy' has no attribute 'chart'
cause Incorrect function name. The primary plotting function in `asciichartpy` is named `plot`, not `chart`.fixCall the correct function: `asciichartpy.plot(...)` or `from asciichartpy import plot; plot(...)`. -
Chart output appears garbled or lines are broken/misaligned.
cause This often occurs when the terminal's character encoding is not correctly interpreted, or due to a font issue, especially on Windows or older terminals.fixEnsure your terminal is using a UTF-8 encoding (e.g., `chcp 65001` on Windows CMD/PowerShell, or check locale settings on Linux/macOS). Using a modern terminal emulator (like Windows Terminal, Alacritty, iTerm2) and a suitable monospaced font (e.g., Fira Code, Source Code Pro) can resolve most rendering issues.
Warnings
- gotcha Input data for plotting must be numeric (list of floats or integers). Passing non-numeric types will result in runtime errors.
- gotcha For plotting multiple series, the input must be a list of lists. A single list is interpreted as a single series.
- gotcha The visual quality of ASCII charts can vary depending on your terminal emulator, font, and window width. Charts might appear truncated or misaligned in narrow terminals or with non-monospaced fonts.
Install
-
pip install asciichartpy
Imports
- plot
from asciichartpy import plot
Quickstart
import asciichartpy
import math
# Generate some sample data (a sine wave)
series_data = [2 * math.sin(i / 10.0) + 5 for i in range(120)]
# Plot the series with a specified height
chart_output = asciichartpy.plot(series_data, {'height': 10})
print(chart_output)
# Plot multiple series
series_data_2 = [1 * math.cos(i / 15.0) + 5 for i in range(120)]
multi_series_output = asciichartpy.plot([series_data, series_data_2], {'height': 12})
print("\n--- Multiple Series ---\n")
print(multi_series_output)