一个简单的python库,将数据打印为ascii柱状图。

ascii_graph的Python项目详细描述


py ascii图形

一个简单的python库,将数据打印为ascii直方图

Travis CIPyPI versionJoin the chat at https://gitter.im/kakwa/py-ascii-graphhttps://coveralls.io/repos/kakwa/py-ascii-graph/badge.svg?branch=masterDocumentation Status
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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在搜索二进制搜索树时遇到问题   当try block中的多行抛出异常时,java使用TryWithResources而不是finally block   java什么时候需要动态多态性(与静态多态性相比)?   从对象类型的角度来看,java的子类是否与racine类等价?   JavaSpring数据JDBConetomany关系会导致大量日志警告   Java:无法更改响应标头中的“ContentDisposition”属性   Java:我可以直接初始化函数而不将其转换为变量吗?   java do,而游标仅从数组返回3个值   java StoredProcedureQuery多输出类型   java ForLoops最大和最小数   如何在java中的任何机器上读取文本文件   java从嵌套标记中获取XML字符串中包含的值   java如何解决Spring批处理作业运行期间的连接重置异常?   我在运行时创建的java Swing组件没有显示在JPanel中   Apache Jena:Error:“java.lang.NoClassDefFoundError:org/Apache/Jena/riot/RDFDataMgr”   java访问嵌套接口数据变量   java如果CopyOnWriteArrayList中的项目被不同的线程更新和读取,我需要同步它们吗?   在Java数组中不断迭代   java组织。贾维斯。常见的例外JaversException:NOT_INSTANCE_OF:无法为EntityType创建InstanceId