Skip to content

Commit 9d9db78

Browse files
committed
started demo mode. added tables to titles
1 parent 74c344c commit 9d9db78

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

bashplotlib/hist.pyc

-4.26 KB
Binary file not shown.

bashplotlib/histogram.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,44 @@ def calc_bins(n, min_val, max_val, h=None):
1414
yield b
1515

1616
def read_numbers(numbers):
17+
"read the input data in the most optimal way"
1718
if isinstance(numbers, list):
1819
for n in numbers:
20+
n = str(n)
1921
yield float(n.strip())
2022
else:
2123
for n in open(numbers):
2224
yield float(n.strip())
2325

26+
def run_demo():
27+
"demo the product"
28+
#plotting a histogram
29+
print "plotting a basic histogram"
30+
print "plot_hist('./data/exp.txt')"
31+
print "hist -f ./data/exp.txt"
32+
print "cat ./data/exp.txt | hist"
33+
plot_hist('./data/exp.txt')
34+
print "*"*80
35+
#with colors
36+
print "histogram with colors"
37+
print "plot_hist('./data/exp.txt', colour='blue')"
38+
print "hist -f ./data/exp.txt -c blue"
39+
plot_hist('./data/exp.txt', colour='blue')
40+
print "*"*80
41+
#changing the shape of the point
42+
print "changing the shape of the bars"
43+
print "plot_hist('./data/exp.txt', pch='.')"
44+
print "hist -f ./data/exp.txt -p ."
45+
plot_hist('./data/exp.txt', pch='.')
46+
print "*"*80
47+
#chagning the size of the plot
48+
print "chagning the size of the plot"
49+
print "plot_hist('./data/exp.txt', height=35.0, bincount=40)"
50+
print "hist -f ./data/exp.txt -s 35.0 -b 40"
51+
plot_hist('./data/exp.txt', height=35.0, bincount=40)
52+
2453
def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title="", xlab=None):
2554
"plot a histogram given a file of numbers"
26-
#first apss
2755
if pch is None:
2856
pch = "o"
2957

@@ -55,7 +83,9 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title="",
5583
ys.reverse()
5684

5785
nlen = max(len(str(min_y)), len(str(max_y))) + 1
58-
print title.center(len(hist) + nlen + 1)
86+
87+
if title:
88+
print box_text(title, len(hist)*2, nlen)
5989
print
6090
used_labs = set()
6191
for y in ys:
@@ -119,16 +149,19 @@ def plot_hist(f, height=20.0, bincount=None, pch="o", colour="white", title="",
119149
parser.add_option('-x', '--xlab', help='label bins on x-axis', default=None, action="store_true", dest='x')
120150
parser.add_option('-c', '--colour', help='colour of the plot (%s)' % ", ".join([c for c in bcolours.keys() if c != 'ENDC']),
121151
default='white', dest='colour')
152+
parser.add_option('-d', '--demo', help='run demos', action='store_true', dest='demo')
122153

123154
(opts, args) = parser.parse_args()
124155

125156
if opts.f is None:
126157
if len(args) > 0:
127158
opts.f = args[0]
128-
else:
159+
elif opts.demo is False:
129160
opts.f = sys.stdin.readlines()
130161

131-
if opts.f:
162+
if opts.demo:
163+
run_demo()
164+
elif opts.f:
132165
plot_hist(opts.f, opts.h, opts.b, opts.p, opts.colour, opts.t, opts.x)
133166
else:
134167
print "nothing to plot!"

bashplotlib/scatter.pyc

-2.95 KB
Binary file not shown.

bashplotlib/scatterplot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
2828
xs = [i[0] for i in data]
2929
ys = [i[1] for i in data]
3030
else:
31-
xs = [float(row.strip()) for row in open(xs)]
32-
ys = [float(row.strip()) for row in open(ys)]
31+
xs = [float(str(row).strip()) for row in open(xs)]
32+
ys = [float(str(row).strip()) for row in open(ys)]
3333

3434
colour = get_colour(colour)
3535

3636
plotted = set()
3737

38-
print title.center(2*len(get_scale(xs, False, size))+2)
38+
if title:
39+
print box_text(title, 2*len(get_scale(xs, False, size))+1)
3940

4041
print "-"*(2*len(get_scale(xs, False, size))+2)
4142
for y in get_scale(ys, True, size):

bashplotlib/utils/__init__.pyc

36 Bytes
Binary file not shown.

bashplotlib/utils/commandhelp.pyc

36 Bytes
Binary file not shown.

bashplotlib/utils/helpers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ def drange(start, stop, step=1.0):
3636
yield r
3737
r += step
3838

39-
def box_text(text, width):
40-
box = "="*(width+4) + "\n"
41-
box += "||" + text.center(width) + "||" + "\n"
42-
box += "="*(width+4)
39+
def box_text(text, width, offset=0):
40+
box = " "*offset + "-"*(width+2) + "\n"
41+
box += " "*offset + "|"+ text.center(width) + "|" + "\n"
42+
box += " "*offset + "-"*(width+2)
4343
return box
4444

4545

46-
print box_text("HELLO", 20)

bashplotlib/utils/helpers.pyc

527 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)