Sparklines is a Python library that generates text-only sparklines using Unicode characters. It's designed for displaying compact, inline visualizations of numerical data, primarily suitable for command-line interfaces or plain text environments. The current version is 0.7.0. Releases are infrequent, focusing on stability and minor enhancements.
pip install sparklinesVerified import paths — ran on the pinned version, not inferred.
The `sparklines` function takes a list of numbers and returns an iterable of strings, each representing a line of the sparkline. You can iterate over these lines to print a multi-line sparkline. Optional arguments allow for customization like setting minimum/maximum values, number of output lines, and character styles.
Test rendering in target environments. Ensure a Unicode-compatible font and terminal are used. Consider adjusting `num_lines` for simpler output if display issues persist.
For data with significant negative values, consider normalizing your data to a positive range before passing it to `sparklines`, or use a different visualization library if precise negative value representation is critical. The library can issue warnings for negative values if configured.
Adjust expectations for text-based visualizations. If smooth, high-resolution line graphs are required, a graphical plotting library (e.g., Matplotlib, Plotly) should be used instead.
pip install sparklines
import sparklines output = sparklines.sparklines([1, 5, 2, 8])
from sparklines import sparklines output = sparklines([1, 5, 2, 8])
from sparklines import sparklines output = sparklines([1, 5, 2, 8])