Termgraph

A few months back I needed a terminal charting tool to quickly create a simple graph.

We had a recruiting competition in BigPanda, and I wanted to draw a bar graph in my terminal to display the employees’ leaderboard. I ended up using the powerful yet complicated gnuplot, a task which took longer than I expected.

Today I learned about Termgraph, a Python-based command line tool to draw simple terminal graphs.

Usage

  1. Create the data file

    • Two or more columns , or space separated. The first column is the label and the rest are the numbered values (at least one)
    • To add categories write @ followed by the category labels.
  2. Execute the command:

    $ termgraph <data-file> <options>
    

Example

Let’s say we wanna draw a graph of a Git project commit leaderboard. To list the contributors by the number of commits, see my previous post.

This is how the data file[1] will look like:

$ cat leaderboard.dat

erikzaadi,51
dkorn,46
Guy Perkal,5
peroman86,8
Spyes,4
Tal Kimhi,1
pinikeizman,3

And all we need to do is run:

$ termgraph --title "Sentinel Commit Leaderboard" leaderboard.dat --format '{:.0f}'

# Sentinel Commit Leaderboard

erikzaadi  : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 51
dkorn      : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 46
Guy Perkal : ▇▇▇▇ 5
peroman86  : ▇▇▇▇▇▇▇ 8
Spyes      : ▇▇▇ 4
Tal Kimhi  : ▏ 1
pinikeizman: ▇▇ 3

Notice I used the --title option and --format '{:.0f}' to display integers, there are many other eye candies[2] to play with.

The coolest one IMO is the --custom-tick option which allows emojis!

$ termgraph --title "Sentinel Commit Leaderboard" leaderboard.dat --format '{:.0f}' --custom-tick '🐙'

# Sentinel Commit Leaderboard

erikzaadi  : 🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙 51
dkorn      : 🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙🐙 46
Guy Perkal : 🐙🐙🐙🐙 5
peroman86  : 🐙🐙🐙🐙🐙🐙🐙 8
Spyes      : 🐙🐙🐙 4
Tal Kimhi  :  1
pinikeizman: 🐙🐙 3

Installation

Using PyPI

$ pip3 install termgraph

[1] For more complex data file examples check out this dir in the project GitHub repo.

[2] Use colors:

Multi variable bar chart with colors

Stack the data

Multi variable stacked bar chart with colors

Calendar Heatmap

Calendar Heatmap

comments powered by Disqus