11#!/usr/bin/python
22import math
3- from collections import Counter
43import optparse
54import sys
65from utils .helpers import *
7-
6+ from utils . commandhelp import hist
87
98def calc_bins (n , min_val , max_val , h = None ):
109 "calculate number of bins for the histogram"
@@ -47,7 +46,7 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
4746 for number in read_numbers (f ):
4847 for i , b in enumerate (bins ):
4948 if number < b :
50- hist [i - 1 ] += 1
49+ hist [i ] += 1
5150 # print "breaking"
5251 break
5352
@@ -57,7 +56,6 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
5756 ys .reverse ()
5857
5958 nlen = max (len (str (min_y )), len (str (max_y ))) + 1
60- nlen = 20
6159 print title .center (len (hist ) + nlen + 1 )
6260 print
6361 used_labs = set ()
@@ -67,7 +65,7 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
6765 ylab = ""
6866 else :
6967 used_labs .add (ylab )
70- ylab + = " " * (nlen - len (ylab )) + "|"
68+ ylab = " " * (nlen - len (ylab )) + ylab + "|"
7169
7270 print ylab ,
7371
@@ -110,7 +108,8 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
110108
111109if __name__ == "__main__" :
112110
113- parser = optparse .OptionParser ()
111+ parser = optparse .OptionParser (usage = hist ['usage' ])
112+
114113 parser .add_option ('-f' , '--file' , help = 'a file containing a column of numbers' ,
115114 default = None , dest = 'f' )
116115 parser .add_option ('-t' , '--title' , help = 'title for the chart' ,
@@ -120,11 +119,12 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
120119 parser .add_option ('-s' , '--height' , help = 'height of the histogram (in lines)' ,
121120 type = 'int' , default = 20. , dest = 'h' )
122121 parser .add_option ('-p' , '--pch' , help = 'shape of each bar' , default = 'o' , dest = 'p' )
123- parser .add_option ('-c' , '--colour' , help = 'colour of the plot (%s)' % ", " .join (bcolours .keys ()),
122+ parser .add_option ('-c' , '--colour' , help = 'colour of the plot (%s)' % ", " .join ([c for c in bcolours .keys () if c !=
123+ 'ENDC' ]),
124124 default = 'white' , dest = 'colour' )
125125
126126 (opts , args ) = parser .parse_args ()
127-
127+
128128 if opts .f is None :
129129 if len (args ) > 0 :
130130 opts .f = args [0 ]
0 commit comments