• Stars
    star
    3,131
  • Rank 14,231 (Top 0.3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a python command-line tool which draws basic graphs in the terminal

Termgraph

A command-line tool that draws basic graphs in the terminal, written in Python.

Graph types supported:

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

Examples

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

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

An example using stdin and emoji:

echo "Label,3,9,1" | termgraph --custom-tick "😀" --no-label


😀😀😀 3.00
😀😀😀😀😀😀😀😀😀 9.00
😀 1.00

Most results can be copied and pasted wherever you like, since they use standard block characters. However the color charts will not show, since they use terminal escape codes for color. A couple images to show color examples:

termgraph data/ex4.dat --color {blue,red}

Multi variable bar chart with colors

termgraph data/ex7.dat --color {yellow,magenta} --stacked --title "Stacked Data"

Multi variable stacked bar chart with colors

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

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

Calendar Heatmap

Install

Requires Python 3.7+, install from PyPI project

python3 -m pip install termgraph

Note: Be sure your PATH includes the pypi install directory, for me it is ~/.local/bin/

Usage

  • Create data file with two columns either comma or space separated. The first column is your labels, the second column is a numeric data

  • termgraph [datafile]

  • Help: termgraph -h

usage: termgraph.py [-h] [(optional arguments)] [filename]

draw basic graphs on terminal

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

optional arguments:
  -h, --help            show this help message and exit
  --title TITLE         Title of graph
  --width WIDTH         width of graph in characters default:50
  --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
  --version             Display version and exit

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 feature requests or bug reports, use Github Issues. Pull requests are welcome to help fix or add features.

Code contributions: This repository uses the black code formatter to automatically format the code. A Github Action is setup to lint your code, to avoid failures it is recommended to setup your editor to auto format on save.

Thanks to all the contributors!

License

MIT License, see LICENSE.txt

More Repositories

1

working-with-go

A set of example golang code to start learning Go
1,152
star
2

lanyon

markdown web server
CSS
508
star
3

code-syntax-block

A WordPress plugin which extends Gutenberg adding color syntax highlighting to the code block.
CSS
319
star
4

hastie

A static site generator in Python
Python
179
star
5

tsblock

An example WordPress block written in Typescript
TypeScript
25
star
6

fswatch

Python script that monitors a Mac OS X folder and on change syncs with remote site
Python
20
star
7

jot

A simple command-line tool to jot notes
Rust
20
star
8

wpsync

A utility to publish posts and media to your WordPress
Go
10
star
9

templets

WordPress plugin to make it easier to create block patterns.
PHP
10
star
10

juxtapose-block

A block for WordPress that enables drop in side-by-side image comparison
JavaScript
10
star
11

dotfiles

My configuration scripts
Vim Script
10
star
12

php-doge

A basic PHP library for interacting with dogecoind
PHP
9
star
13

oneliner

A command-line tool for saving one line notes in plain text files.
Python
7
star
14

chester-colors

Repo for collecting up Chester color scheems
HTML
7
star
15

ephemeral

A program that delete tweets
Go
5
star
16

qrcode-block

QRCode Block for Gutenberg editor - see step-by-step screencasts at https://mkaz.blog/
JavaScript
5
star
17

mkaz-block-template

A block template
Mustache
4
star
18

mcbain

A WordPress theme for mkaz.blog
PHP
4
star
19

fetcher

A client library to help make HTTP requests a little easier in Go.
Go
4
star
20

carbon

A WordPress theme using React
PHP
3
star
21

light.wtf

Photography Exposure Calculators
JavaScript
3
star
22

tasks

Command-line task todo list
Python
2
star
23

ctrl-alt-vim

A fork of vim-anywhere
Vim Script
2
star
24

neojot

A Neovim plugin for jotting notes
Python
2
star
25

test-block

A block for testing.
JavaScript
2
star
26

copyright-block

A copyright block for WordPress
PHP
2
star
27

octoack

Selectively query GitHub and post to Slack
Rust
2
star
28

gutenpride

A simple example block displaying Gutenberg pride
JavaScript
2
star
29

asciinema-block

A block for WordPress to play asciinema recordings
CSS
1
star
30

wpscrub

A WordPress plugin to remove a few bits
PHP
1
star
31

anim

Simple scripts for creating 2D animation using a camera
Python
1
star
32

browser-pad

A simple HTML page that turns your browser into a basic editor.
HTML
1
star
33

wprs

A toy WordPress client written in Rust
Rust
1
star