• Stars
    star
    117
  • Rank 295,652 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created over 11 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

A simple python lib to print data as ascii histograms

py-ascii-graph

A simple python lib to print data as ascii histograms

Travis CI PyPI version Join the chat at https://gitter.im/kakwa/py-ascii-graph https://coveralls.io/repos/kakwa/py-ascii-graph/badge.svg?branch=master Documentation Status
Git:Github
PyPI:Package
Doc:Documentation
License:MIT
Author:Pierre-Francois Carpentier - copyright 2014

License

py-ascii-graph is released under the MIT License.

Description

py-ascii-graph is a simple python library to build ascii histograms. Just give it a label and a list of tuples (description, value) and it will automaticaly creates a nice histogram, with all the stuff aligned and fitting in a fixed width line (if possible).

py-ascii-graph although comes with a command line utility.

Examples

Library

Simple example:

from ascii_graph import Pyasciigraph

test = [('long_label', 423), ('sl', 1234), ('line3', 531),
    ('line4', 200), ('line5', 834)]

graph = Pyasciigraph()
for line in  graph.graph('test print', test):
    print(line)

Result:

test print
###############################################################################
████████████████████                                            423  long_label
█████████████████████████████████████████████████████████████  1234  sl
██████████████████████████                                      531  line3
█████████                                                       200  line4
█████████████████████████████████████████                       834  line5

Complex examples (colors, different spacing, no label...):

from ascii_graph import Pyasciigraph
from ascii_graph.colors import *
from ascii_graph.colordata import vcolor
from ascii_graph.colordata import hcolor

test = [('long_label', 423), ('sl', 1234), ('line3', 531),
    ('line4', 200), ('line5', 834)]

# One color per line
print('Color example:')
pattern = [Gre, Yel, Red]
data = vcolor(test, pattern)

graph = Pyasciigraph()
for line in graph.graph('vcolor test', data):
    print(line)

# Multicolor on one line
print('\nMultiColor example:')

# Color lines according to Thresholds
thresholds = {
  51:  Gre, 100: Blu, 350: Yel, 500: Red,
}
data = hcolor(test, thresholds)

# graph with colors, power of 1000, different graph symbol,
# float formatting and a few tweaks
graph = Pyasciigraph(
    line_length=120,
    min_graph_length=50,
    separator_length=4,
    multivalue=False,
    human_readable='si',
    graphsymbol='*',
    float_format='{0:,.2f}',
    force_max_value=2000,
    )

for line in graph.graph(label=None, data=data):
    print(line)

Command Line Utility

command line:

$ asciigraph -h
Usage: asciigraph [-l <label>] [-f file] [-s inc|dec] \
   [-c] [-t <first color threshold> [-T <second color threshold>] \
   [-w <number of char>] [-m <min len of char>] [-H] [-M cs|si]

examples:
   printf 'label1:10\nlabel2:100\n' | asciigraph -l 'my graph'
   printf 'label1:1000\nlabel2:20000\n' | asciigraph -l 'my graph' -H -M 'si'
   printf 'l1:100\nl2:1200.42\n' > ./mf; asciigraph -l 'my graph' -f ./mf
   asciigraph -l 'my graph' -f mf -s inc
   asciigraph -l 'my graph' -f mf -s dec -w 60 -m 10
   asciigraph -l 'my graph' -f mf -c -F '{0:,.2f}'
   asciigraph -l 'my graph' -f mf -c -t 5 -T 50


Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  import data from FILE (one data per line,
                        format: <label>:<value>)
  -s SORT, --sort=SORT  sort type: inc (increasing) or dec (decreasing)
  -l LAB, --label=LAB   label of the graph
  -w WIDTH, --width=WIDTH
                        width of the graph
  -m LEN, --min_graph=LEN
                        minimum length of the graph bar
  -c, --color           Color the graph
  -t TC1, --threshold-1=TC1
                        first color threshold, only make sense if --color is
                        passed
  -T TC2, --threshold-2=TC2
                        second color threshold, only make sense if --color is
                        passed
  -H, --human-readable  enable human readable mode (K, M, G, etc)
  -M HR_MODE, --human-readable-mode=HR_MODE
                        Human readable mode ('cs' -> power of 1024 or 'si' ->
                        power of 1000, default: cs)
  -F FORMAT, --float-format=FORMAT
                        float formatting, ex: {0:,.2f}

See the examples/ directory for more examples.

Installation

$ pip install ascii_graph

or

$ easy_install ascii_graph

More Repositories

1

ldapcherry

Web UI for managing users and groups in multiple directory services.
Python
219
star
2

libvisio2svg

Library/Tools to convert Microsoft (MS) Visio documents (VSS and VSD) to SVG
C++
109
star
3

kakwafont

Kakwafont, a 12px monospace bitmap font based on Terminus
Makefile
88
star
4

libemf2svg

Microsoft (MS) EMF to SVG conversion library
C
87
star
5

uts-server

Micro RFC 3161 Time-Stamp server written in C.
C
74
star
6

pylogic

Python Module for Logical Validation (forked from Rob Truxler library)
Python
24
star
7

pygraph_redis

Simple python library to manipulate directed graphs in redis
Python
24
star
8

dnscherry

Small cherrypy application to manage dns zones.
CSS
11
star
9

puppet-samba

Puppet samba module ⛺
Puppet
9
star
10

amkecpak

Amkecpak, a makefile based packaging framework.
Shell
6
star
11

htpasswd-editor

htpasswd-editor is a simple Perl CGI to manage htpasswd files
Perl
6
star
12

dwm-desktop

dwm + configuration + mods + shell utilities
C
6
star
13

talend-codegen

Command line code generation (job export) plugin for talend
Java
5
star
14

wifish

wifish are small scripts to get ride of wicd/NetworkManager
Shell
4
star
15

genautoo

Genautoo: an automated installer for gentoo
Shell
3
star
16

git-create.cgi

Simple CGI to create git repositories
Perl
3
star
17

debian-rpm-build-tools

Debian Packaging of various RPM build tools and dependencies (mock, dnf, etc)
Shell
2
star
18

fradomus

Python library to query french real estate ads website such seloger, pap, etc
Python
2
star
19

cinclude2svg

cinclude2dot + mods + helper script + static site generator
JavaScript
2
star
20

sytadin-scraper

sytadin traffic info scraper written in perl
Perl
2
star
21

mkcomment

mkcomment is a really simple script to make nicely centered comment line
1
star
22

wows-whaling-simulator

Simulator estimating how much you need to whale to get one or more specific ships in Christmas Containers
Go
1
star
23

validate-puppet

Small shell script to validate puppet and erb source code
Shell
1
star
24

python-hoi4tools

Python
1
star
25

mk-sh-skel

just a simple script skeleton initializer
Shell
1
star
26

wows-geometry

World of Warships .geometry (3D model) parser
C
1
star
27

dmenu-user

A small launcher menu based on dmenu
Shell
1
star
28

image-writer

playing around old image writer and appletalk
C
1
star
29

gen-badge

Small shell script to generate a "Travis-CI" like SVG status badges/shields
Shell
1
star
30

thinkfan-sh

simple fan control script for thinkpad
Shell
1
star
31

mystarred

1
star
32

ldapcherry-ppolicy-cracklib

Cracklib password policy plugin for LdapCherry
Python
1
star
33

supybot-plugin-seloger

supybot plugin for seloger
Python
1
star
34

radiateur-linux

A simple linux iso builder transforming a computer into a radiator (boot -> launch stress, that's all)
Shell
1
star
35

tapemgr-124t

Utilities and library to manage a Dell PowerVault 124-t from command line
Perl
1
star
36

trc

tar revision control
Shell
1
star
37

puppet-auto_update

A puppet module auto-updating your Debian/CentOS daily
Puppet
1
star
38

hoi4-production-calculator

HOI4 editor to optimize military factory allocation
Python
1
star
39

collectd-opentsdb

Alternative TSDB writer with inclusion of tag logic and http API support
C
1
star
40

curriculum-vitae

My curriculum vitae
TeX
1
star
41

ansible

My Ansible configuration
Shell
1
star