@@ -21,7 +21,7 @@ def read_numbers(numbers):
2121 for n in open (numbers ):
2222 yield float (n .strip ())
2323
24- def plot_hist (f , height = 20.0 , bincount = None , pch = "o" , colour = "white" , title = "" ):
24+ def plot_hist (f , height = 20.0 , bincount = None , pch = "o" , colour = "white" , title = "" , xlab = None ):
2525 "plot a histogram given a file of numbers"
2626 #first apss
2727 if pch is None :
@@ -47,7 +47,6 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
4747 for i , b in enumerate (bins ):
4848 if number < b :
4949 hist [i ] += 1
50- # print "breaking"
5150 break
5251
5352 min_y , max_y = min (hist .values ()), max (hist .values ())
@@ -79,7 +78,17 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
7978
8079 print " " * (nlen + 1 ) + "-" * len (xs )
8180
82-
81+
82+ if xlab :
83+ for i in range (0 , nlen ):
84+ printcolor (" " * (nlen + 1 ), True , colour )
85+ for x in range (0 , len (hist )):
86+ num = str (bins [x ])
87+ if x % 2 == 0 :
88+ print " " ,
89+ elif i < len (num ):
90+ print num [i ],
91+ print
8392 center = max (map (len , map (str , [n , min_val , mean , max_val ])))
8493 center += 15
8594 print
@@ -92,18 +101,6 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
92101 summary += "|" + ("max value: %f" % max_val ).center (center ) + "|\n "
93102 summary += "-" * (2 + center )
94103 print summary
95- # for i in range(0, nlen):
96- # printcolor(" "*(nlen+1), True, colour)
97- # for x in range(0, len(hist)):
98- # num = str(bins[x])
99- # if x%2==0:
100- # print " ",
101- # elif i < len(num):
102- # print num[i],
103- # print
104- #
105- # summary = "Summary\n--------\nMax: %s\nMin: %s\nCount: %s" % (min_val, max_val, int(n))
106- # print summary
107104
108105
109106if __name__ == "__main__" :
@@ -119,8 +116,8 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
119116 parser .add_option ('-s' , '--height' , help = 'height of the histogram (in lines)' ,
120117 type = 'int' , default = 20. , dest = 'h' )
121118 parser .add_option ('-p' , '--pch' , help = 'shape of each bar' , default = 'o' , dest = 'p' )
122- parser .add_option ('-c ' , '--colour ' , help = 'colour of the plot (%s)' % ", " . join ([ c for c in bcolours . keys () if c !=
123- 'ENDC' ]),
119+ parser .add_option ('-x ' , '--xlab ' , help = 'label bins on x-axis' , default = None , action = "store_true" , dest = 'x' )
120+ parser . add_option ( '-c' , '--colour' , help = 'colour of the plot (%s)' % ", " . join ([ c for c in bcolours . keys () if c != 'ENDC' ]),
124121 default = 'white' , dest = 'colour' )
125122
126123 (opts , args ) = parser .parse_args ()
@@ -132,7 +129,7 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title=""):
132129 opts .f = sys .stdin .readlines ()
133130
134131 if opts .f :
135- plot_hist (opts .f , opts .h , opts .b , opts .p , opts .colour , opts .t )
132+ plot_hist (opts .f , opts .h , opts .b , opts .p , opts .colour , opts .t , opts . x )
136133 else :
137134 print "nothing to plot!"
138135
0 commit comments