py-ascii-graph
A simple python lib to print data as ascii histograms
- Git:
- PyPI:
- Doc:
- 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
Metadata
Release files for ascii-graph 1.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ascii_graph-1.5.2.tar.gz | 25.3 kB | Without provenance | Details for ascii_graph-1.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ascii_graph-1.5.2-py3-none-any.whl | Python 3 | none | any | Details for ascii_graph-1.5.2-py3-none-any.whl |
Total release size: 37.1 kB
Release files / ascii_graph-1.5.2.tar.gz
| Download URL | ascii_graph-1.5.2.tar.gz |
|---|---|
| Size | 25.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32ec5e8af8ac1b285cb0c3d1715b3e44d2152bff71f27cde60c3b5d23f98e0a4
|
|
BLAKE2b-256 checksum How to use checksums |
965a4cd3cdd64c71b709a8ca747447b4821b8d291e0e3a7ebeaca61d702bda2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / ascii_graph-1.5.2-py3-none-any.whl
| Download URL | ascii_graph-1.5.2-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82a128971cf189e37131239f89fdf2dac769672e2c30de187e7aa5c345e103e2
|
|
BLAKE2b-256 checksum How to use checksums |
8d56c5929896ee2d533a382c2b7a9cec7a9f58970aa04b21ccf8c31f758cd4f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for ascii-graph 1.5.2
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.