Package: ascii_graph
py-ascii-graphA simple python lib to print data as ascii histogramsGit:GithubPyPI:PackageDoc:DocumentationLicense:MITAuthor:Pierre-Francois Carpentier - copyright 2014Licensepy-ascii-graph is released under the MIT License.Descriptionpy-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.ExamplesLibrarySimple example:fromascii_graphimportPyasciigraphtest=[('long_label',423),('sl',1234),('line3',531),('line4',200),('line5',834)]graph=Pyasciigraph()forlineingraph.graph('test print',test):print(line)Result:testprint###############################################################################████████████████████423long_label█████████████████████████████████████████████████████████████1234sl██████████████████████████531line3█████████200line4█████████████████████████████████████████834line5Complex examples (colors, different spacing, no label…):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)Command Line Utilitycommand line:$asciigraph-hUsage:asciigraph[-l<label>][-ffile][-sinc|dec]\[-c][-t<firstcolorthreshold>[-T<secondcolorthreshold>]\[-w<numberofchar>][-m<minlenofchar>][-H][-Mcs|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./mfasciigraph-l'my graph'-fmf-sincasciigraph-l'my graph'-fmf-sdec-w60-m10asciigraph-l'my graph'-fmf-c-F'{0:,.2f}'asciigraph-l'my graph'-fmf-c-t5-T50Options:-h,--helpshowthishelpmessageandexit-fFILE,--file=FILEimportdatafromFILE(onedataperline,format:<label>:<value>)-sSORT,--sort=SORTsorttype:inc(increasing)ordec(decreasing)-lLAB,--label=LABlabelofthegraph-wWIDTH,--width=WIDTHwidthofthegraph-mLEN,--min_graph=LENminimumlengthofthegraphbar-c,--colorColorthegraph-tTC1,--threshold-1=TC1firstcolorthreshold,onlymakesenseif--colorispassed-TTC2,--threshold-2=TC2secondcolorthreshold,onlymakesenseif--colorispassed-H,--human-readableenablehumanreadablemode(K,M,G,etc)-MHR_MODE,--human-readable-mode=HR_MODEHumanreadablemode('cs'->powerof1024or'si'->powerof1000,default:cs)-FFORMAT,--float-format=FORMATfloatformatting,ex:{0:,.2f}See the examples/ directory for more examples.Installation$pipinstallascii_graphor$easy_installascii_graph