Skip to content

Commit ce863ce

Browse files
committed
added title to hist
1 parent a14c5d2 commit ce863ce

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

bin/hist.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

bin/utils/helpers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ def get_colour(colour):
1717

1818
def printcolor(txt, sameline=False, color=get_colour("white")):
1919
if sameline:
20-
print color + txt + bcolours["ENDC"],
20+
if color=='\033[97m':
21+
print txt,
22+
else:
23+
print color + txt + bcolours["ENDC"],
2124
else:
22-
print color + txt + bcolours["ENDC"]
25+
if color=='\033[97m':
26+
print txt
27+
else:
28+
print color + txt + bcolours["ENDC"]
2329

2430
def drange(start, stop, step=1.0):
2531
"generate between 2 numbers w/ optional step"
2632
r = start
2733
while r < stop:
2834
yield r
29-
r += step
35+
r += step

bin/utils/helpers.pyc

57 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)