一个简单的python库,将数据打印为ascii柱状图。
ascii_graph的Python项目详细描述
py ascii图形
一个简单的python库,将数据打印为ascii直方图
Git: | Github |
---|---|
PyPI: | Package |
Doc: | Documentation |
License: | MIT |
Author: | Pierre-Francois Carpentier - copyright 2014 |
许可证
py ascii图形是在mit许可下发布的。
说明
py ascii graph是一个构建ascii柱状图的简单python库。 给它一个标签和一个元组列表(描述,值) 它会自动创建一个很好的直方图, 把所有的东西都对齐,并固定在一条宽度的直线上(如果可能的话)。
py ascii图形虽然带有命令行实用程序。
示例
库
简单示例:
fromascii_graphimportPyasciigraphtest=[('long_label',423),('sl',1234),('line3',531),('line4',200),('line5',834)]graph=Pyasciigraph()forlineingraph.graph('test print',test):print(line)
结果:
test print ############################################################################### ████████████████████ 423 long_label █████████████████████████████████████████████████████████████ 1234 sl ██████████████████████████ 531 line3 █████████ 200 line4 █████████████████████████████████████████ 834 line5
复杂示例(颜色、不同间距、无标签…):
fromascii_graphimportPyasciigraphfromascii_graph.colorsimport*fromascii_graph.colordataimportvcolorfromascii_graph.colordataimporthcolortest=[('long_label',423),('sl',1234),('line3',531),('line4',200),('line5',834)]# One color per lineprint('Color example:')pattern=[Gre,Yel,Red]data=vcolor(test,pattern)graph=Pyasciigraph()forlineingraph.graph('vcolor test',data):print(line)# Multicolor on one lineprint('\nMultiColor example:')# Color lines according to Thresholdsthresholds={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 tweaksgraph=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,)forlineingraph.graph(label=None,data=data):print(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}
有关更多示例,请参见examples/目录。
安装
$ pip install ascii_graph
或
$ easy_install ascii_graph