Skip to main content

Termgraph

A command-line tool and Python library that draws basic graphs in the terminal.

Graph types supported:

  • Bar Graphs
  • Color charts
  • Multi-variable
  • Stacked charts
  • Histograms
  • Horizontal or Vertical
  • Calendar heatmaps
  • Emoji!

Quick Start

Command Line Usage

$ termgraph data/ex1.dat

# Reading data from data/ex1.dat

2007: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 183.32
2008: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 231.23
2009: ▇ 16.43
2010: ▇▇▇▇ 50.21
2011: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 508.97
2012: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 212.05
2014: ▏ 1.00

Python Module Usage

from termgraph import Data, Args, BarChart

# Create data
data = Data([[10], [25], [50], [40]], ["Q1", "Q2", "Q3", "Q4"])

# Configure chart options
args = Args(
    title="Quarterly Sales",
    width=50,
    format="{:.0f}",
    suffix="K"
)

# Create and display chart
chart = BarChart(data, args)
chart.draw()

Output:

# Quarterly Sales

Q1: ▇▇▇▇▇▇▇▇▇▇ 10K
Q2: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25K
Q3: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50K
Q4: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 40K

More Examples

Fixed Scale

Use --scale to compare charts across multiple runs without changing the number of units represented by each tick:

printf 'A 6\nB 12\n' | termgraph --scale 4 --format '{:g}'
A: ▇▇ 6
B: ▇▇▇ 12

Each tick represents up to four units. Positive values round up to a whole tick and zero draws no bar. The scale must be positive and finite, and the data must be finite and non-negative. --scale overrides --width without clipping bars. It supports horizontal, stacked, and vertical bar charts; stacked segments round independently. It cannot be combined with --different-scale, --histogram, or --calendar.

The same option is available in Python: BarChart(data, Args(scale=4)).draw(). Omitting it keeps the existing automatic scaling.

Custom Tick Marks

An example using emoji as custom tick:

termgraph data/ex1.dat --custom-tick "🏃" --width 20 --title "Running Data"

# Running Data

2007: 🏃🏃🏃🏃🏃🏃🏃 183.32
2008: 🏃🏃🏃🏃🏃🏃🏃🏃🏃 231.23
2009:  16.43
2010: 🏃 50.21
2011: 🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃🏃 508.97
2012: 🏃🏃🏃🏃🏃🏃🏃🏃 212.05
2014:  1.00

Color Charts

Note: Color charts use ANSI escape codes, so may not be able to copy/paste from terminal into other uses.

$ termgraph data/ex4.dat --color {cyan/yellow} --space-between

Bar chart with multiple variables


termgraph data/ex7.dat --color {green,magenta} --stacked

Stacked Bar Chart

Count-first input

Termgraph accepts counts before text labels, so you can pipe the output of sort | uniq -c directly into it:

printf '%s\n' 'update settings' 'create' 'update settings' | sort | uniq -c | termgraph

No extra flag or column-swapping command is needed. For example, 2 update settings is read as the label update settings with the value 2.

With whitespace-separated input, numeric words inside a label are also read as values. For labels such as HTTP 404, use a delimiter to keep the entire label in one field, for example 2,HTTP 404. A label that is entirely numeric is ambiguous in count-first input; use the usual label-first order for those rows, such as 404,2. See file and standard-input parsing for details.

Calendar Heatmap

Calendar Heatmap, expects first column to be date in yyyy-mm-dd

$ termgraph --calendar --start-dt 2017-07-01 data/cal.dat

Calendar Heatmap

Usage

Command Line Interface

  • Create a data file with labels and numeric values, separated by commas or whitespace. Text labels can come before or after the values. If every field is numeric, the first field is treated as the label. See the sort | uniq -c example for count-first input.

  • termgraph [datafile]

  • Help: termgraph -h

Command Line Arguments

usage: termgraph [-h] [options] [filename]

draw basic graphs on terminal

positional arguments:
  filename              data file name (comma or space separated). Defaults to stdin.

options:
  -h, --help            show this help message and exit
  --title TITLE         Title of graph
  --width WIDTH         width of graph in characters default:50
  --scale SCALE         fixed units per tick for non-negative bar charts; overrides --width
  --format FORMAT       format specifier to use.
  --suffix SUFFIX       string to add as a suffix to all data points.
  --no-labels           Do not print the label column
  --no-values           Do not print the values at end
  --space-between       Print a new line after every field
  --color [COLOR ...]   Graph bar color( s )
  --vertical            Vertical graph
  --stacked             Stacked bar graph
  --histogram           Histogram
  --bins BINS           Bins of Histogram
  --different-scale     Categories have different scales.
  --calendar            Calendar Heatmap chart
  --start-dt START_DT   Start date for Calendar chart
  --custom-tick CUSTOM_TICK
                        Custom tick mark, emoji approved
  --delim DELIM         Custom delimiter, default , or space
  --verbose             Verbose output, helpful for debugging
  --label-before        Display the values before the bars
  --no-readable         Disable the readable numbers
  --percentage          Display the number in percentage
  --version             Display version and exit

Python API

All chart types are available as classes:

from termgraph import (
    Data, Args,
    BarChart, StackedChart, VerticalChart, HistogramChart
)

# Basic setup
data = Data([[10], [20]], ["A", "B"])
args = Args(title="My Chart")

# Choose your chart type
chart = BarChart(data, args)        # Horizontal bars
# chart = StackedChart(data, args)  # Stacked bars
# chart = VerticalChart(data, args) # Vertical bars
# chart = HistogramChart(data, args) # Histogram

chart.draw()

📚 Complete Python API Documentation

For comprehensive examples, detailed API reference, and advanced usage patterns, see the complete documentation:

Quick Args options:

  • title: Chart title
  • width: Width in characters (default: 50)
  • scale: Fixed units per tick for non-negative bar charts (default: None)
  • format: Number format string (default: "{:<5.2f}")
  • suffix: Add suffix to all values
  • no_labels: Don't show labels
  • no_values: Don't show values
  • colors: List of color names

Background

I wanted a quick way to visualize data stored in a simple text file. I initially created some scripts in R that generated graphs but this was a two step process of creating the graph and then opening the generated graph.

After seeing command-line sparklines I figured I could do the same thing using block characters for bar charts.

Contribute

All contributions are welcome! For detailed information about the project structure, development workflow, and contribution guidelines, please see CONTRIBUTING.md.

Quick Start:

  • 🐛 Bug reports and 🚀 feature requests: Use GitHub Issues
  • 🔧 Code contributions: See our development workflow
  • 📚 Documentation: Help improve our guides and examples

Code Quality: We use ruff for linting and formatting, mypy for type checking, and maintain comprehensive test coverage.

Thanks to all the contributors!

License

MIT License, see LICENSE.txt

Metadata

Release files for termgraph 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for termgraph 0.8.1
File Size Uploaded Provenance Actions
termgraph-0.8.1.tar.gz 470.3 kB Without provenance Details for termgraph-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for termgraph 0.8.1
File Interpreter ABI Platform Actions
termgraph-0.8.1-py3-none-any.whl Python 3 none any Details for termgraph-0.8.1-py3-none-any.whl

Total release size: 490.7 kB

Release files / termgraph-0.8.1.tar.gz

Download URL termgraph-0.8.1.tar.gz
Size 470.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3bf9f3684fcb0443735fd4625e43489ab7a2dbd828edc8bc9135fb1398e10410
BLAKE2b-256 checksum
How to use checksums
78820954112fddc3b95cceed81eb538ad85685d2e911e0ba8de63708acc60489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / termgraph-0.8.1-py3-none-any.whl

Download URL termgraph-0.8.1-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2facbf2f54a833a4b4f7f458da0880aa01e3da52a557de6fbb3f76d392bdb9f4
BLAKE2b-256 checksum
How to use checksums
155c2c77ba0159633514def05ffd7f8ba2c459c23c888294bc71fc41f50fbfa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for termgraph 0.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page