33from collections import Counter
44import optparse
55import sys
6+ from utils .helpers import *
67
78
8- bcolours = {
9- "white" : '\033 [97m' ,
10- "aqua" : '\033 [96m' ,
11- "pink" : '\033 [95m' ,
12- "blue" : '\033 [94m' ,
13- "yellow" : '\033 [93m' ,
14- "green" : '\033 [92m' ,
15- "red" : '\033 [91m' ,
16- "grey" : '\033 [90m' ,
17- "ENDC" : '\033 [0m'
18- }
19-
20- def get_colour (colour ):
21- return bcolours .get (colour , bcolours ['white' ])
22-
23- def printcolor (txt , sameline = False , color = get_colour ("white" )):
24- if sameline :
25- print color + txt + bcolours ["ENDC" ],
26- else :
27- print color + txt + bcolours ["ENDC" ]
28-
29- def drange (start , stop , step = 1.0 ):
30- "generate between 2 numbers w/ optional step"
31- r = start
32- while r < stop :
33- yield r
34- r += step
35-
369def calc_bins (n , min_val , max_val , h = None ):
3710 "calculate number of bins for the histogram"
3811 if not h :
@@ -90,7 +63,7 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white"):
9063 ylab = str (y )
9164 ylab += " " * (nlen - len (ylab )) + "|"
9265
93- printcolor ( ylab , True , colour )
66+ print ylab ,
9467
9568 for i in range (len (hist )):
9669 if y < hist [i ]:
@@ -100,16 +73,16 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white"):
10073 print
10174 xs = hist .keys () * 2
10275
103- printcolor ( " " * (nlen + 1 ) + "-" * len (xs ), False , colour )
76+ print " " * (nlen + 1 ) + "-" * len (xs )
10477
10578 for i in range (0 , nlen ):
10679 printcolor (" " * (nlen + 1 ), True , colour )
10780 for x in range (0 , len (hist )):
10881 num = str (bins [x ])
10982 if x % 2 == 0 :
110- printcolor ( " " , True , colour )
83+ print " " ,
11184 elif i < len (num ):
112- printcolor ( num [i ], True , colour )
85+ print num [i ],
11386 print
11487
11588 summary = "Summary\n --------\n Max: %s\n Min: %s\n Count: %s" % (min_val , max_val , int (n ))
@@ -126,7 +99,8 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white"):
12699 parser .add_option ('-s' , '--height' , help = 'height of the histogram (in lines)' ,
127100 default = 20 , dest = 'h' )
128101 parser .add_option ('-p' , '--pch' , help = 'shape of each bar' , default = 'o' , dest = 'p' )
129- parser .add_option ('-c' , '--colour' , help = 'colour of the plot' , default = 'white' , dest = 'colour' )
102+ parser .add_option ('-c' , '--colour' , help = 'colour of the plot (%s)' % ", " .join (bcolours .keys ()),
103+ default = 'white' , dest = 'colour' )
130104
131105 (opts , args ) = parser .parse_args ()
132106
0 commit comments