@@ -53,7 +53,7 @@ def run_demo():
5353 print "hist -f ./data/exp.txt -s 35.0 -b 40"
5454 plot_hist ('./data/exp.txt' , height = 35.0 , bincount = 40 )
5555
56- def plot_hist (f , height = 20.0 , bincount = None , binwidth = None , pch = "o" , colour = "white" , title = "" , xlab = None , showSummary = False ):
56+ def plot_hist (f , height = 20.0 , bincount = None , binwidth = None , pch = "o" , colour = "white" , title = "" , xlab = None , showSummary = False , regular = False ):
5757 """make a histogram
5858
5959 Keyword arguments:
@@ -65,6 +65,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
6565 title -- title at the top of the plot
6666 xlab -- boolen value for whether or not to display x-axis labels
6767 showSummary -- boolean value for whether or not to display a summary
68+ regular -- boolean value for whether or not to start y-labels at 0
6869 """
6970
7071 if pch is None :
@@ -98,7 +99,17 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
9899
99100 min_y , max_y = min (hist .values ()), max (hist .values ())
100101
101- ys = list (drange (max (min_y , 1 ), max_y + 1 , (max_y - min_y )/ height ))
102+ start = max (min_y , 1 )
103+ stop = max_y + 1
104+ if regular :
105+ start = 1
106+
107+ if height is None :
108+ height = stop - start
109+ if height > 20 :
110+ height = 20
111+
112+ ys = list (drange (start , stop , float (stop - start )/ height ))
102113 ys .reverse ()
103114
104115 nlen = max (len (str (min_y )), len (str (max_y ))) + 1
@@ -170,13 +181,14 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
170181 parser .add_option ('-w' , '--binwidth' , help = 'width of bins in the histogram' ,
171182 type = 'float' , default = None , dest = 'binwidth' )
172183 parser .add_option ('-s' , '--height' , help = 'height of the histogram (in lines)' ,
173- type = 'int' , default = 20. , dest = 'h' )
184+ type = 'int' , default = None , dest = 'h' )
174185 parser .add_option ('-p' , '--pch' , help = 'shape of each bar' , default = 'o' , dest = 'p' )
175186 parser .add_option ('-x' , '--xlab' , help = 'label bins on x-axis' , default = None , action = "store_true" , dest = 'x' )
176187 parser .add_option ('-c' , '--colour' , help = 'colour of the plot (%s)' % ", " .join ([c for c in bcolours .keys () if c != 'ENDC' ]),
177188 default = 'white' , dest = 'colour' )
178189 parser .add_option ('-d' , '--demo' , help = 'run demos' , action = 'store_true' , dest = 'demo' )
179190 parser .add_option ('-n' , '--nosummary' , help = 'hide summary' , action = 'store_false' , dest = 'showSummary' , default = True )
191+ parser .add_option ('-r' , '--regular' , help = 'use regular y-scale (0 - maximum y value), instead of truncated y-scale (minimum y-value - maximum y-value)' , default = False , action = "store_true" , dest = 'regular' )
180192
181193 (opts , args ) = parser .parse_args ()
182194
@@ -189,7 +201,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
189201 if opts .demo :
190202 run_demo ()
191203 elif opts .f :
192- plot_hist (opts .f , opts .h , opts .b , opts .binwidth , opts .p , opts .colour , opts .t , opts .x , opts .showSummary )
204+ plot_hist (opts .f , opts .h , opts .b , opts .binwidth , opts .p , opts .colour , opts .t , opts .x , opts .showSummary , opts . regular )
193205 else :
194206 print "nothing to plot!"
195207
0 commit comments