@@ -22,7 +22,7 @@ def read_numbers(numbers):
2222 for n in open (numbers ):
2323 yield float (n .strip ())
2424
25- def plot_hist (f , height = 20 , bincount = None , pch = "o" , colour = "white" ):
25+ def plot_hist (f , height = 20 , bincount = None , pch = "o" , colour = "white" , title = "" ):
2626 "plot a histogram given a file of numbers"
2727 #first apss
2828 if pch is None :
@@ -58,7 +58,8 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white"):
5858
5959 nlen = max (len (str (min_y )), len (str (max_y ))) + 1
6060
61-
61+ print title .center (len (hist ) + nlen + 1 )
62+ print
6263 for y in ys :
6364 ylab = str (y )
6465 ylab += " " * (nlen - len (ylab )) + "|"
@@ -94,6 +95,8 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white"):
9495 parser = optparse .OptionParser ()
9596 parser .add_option ('-f' , '--file' , help = 'a file containing a column of numbers' ,
9697 default = None , dest = 'f' )
98+ parser .add_option ('-t' , '--title' , help = 'title for the chart' ,
99+ default = "" , dest = 't' )
97100 parser .add_option ('-b' , '--bins' , help = 'number of bins in the histogram' ,
98101 default = None , dest = 'b' )
99102 parser .add_option ('-s' , '--height' , help = 'height of the histogram (in lines)' ,
@@ -107,5 +110,5 @@ def plot_hist(f, height=20, bincount=None, pch="o", colour="white"):
107110 if opts .f is None :
108111 opts .f = args [0 ]
109112
110- plot_hist (opts .f , opts .h , opts .b , opts .p , opts .colour )
113+ plot_hist (opts .f , opts .h , opts .b , opts .p , opts .colour , opts . t )
111114
0 commit comments