|
2 | 2 |
|
3 | 3 | import math |
4 | 4 | import optparse |
| 5 | +import os |
| 6 | +from os.path import dirname |
5 | 7 | import sys |
6 | 8 | from utils.helpers import * |
7 | 9 | from utils.commandhelp import hist |
@@ -30,32 +32,47 @@ def read_numbers(numbers): |
30 | 32 | for n in open(numbers): |
31 | 33 | yield float(n.strip()) |
32 | 34 |
|
| 35 | + |
33 | 36 | def run_demo(): |
34 | | - "demo the product" |
| 37 | + """ |
| 38 | + Run a demonstration |
| 39 | + """ |
| 40 | + module_dir = dirname(dirname(os.path.realpath(__file__))) |
| 41 | + demo_file = os.path.join(module_dir, 'examples/data/exp.txt') |
| 42 | + |
| 43 | + if not os.path.isfile(demo_file): |
| 44 | + sys.stderr.write("demo input file not found!\n") |
| 45 | + sys.stderr.write("run the downloaddata.sh script in the example first\n") |
| 46 | + sys.exit(1) |
| 47 | + |
35 | 48 | #plotting a histogram |
36 | 49 | print "plotting a basic histogram" |
37 | | - print "plot_hist('./data/exp.txt')" |
38 | | - print "hist -f ./data/exp.txt" |
39 | | - print "cat ./data/exp.txt | hist" |
40 | | - plot_hist('./data/exp.txt') |
41 | | - print "*"*80 |
| 50 | + print "plot_hist('%s')" % demo_file |
| 51 | + print "hist -f %s" % demo_file |
| 52 | + print "cat %s | hist" % demo_file |
| 53 | + plot_hist(demo_file) |
| 54 | + print "*" * 80 |
| 55 | + |
42 | 56 | #with colors |
43 | 57 | print "histogram with colors" |
44 | | - print "plot_hist('./data/exp.txt', colour='blue')" |
45 | | - print "hist -f ./data/exp.txt -c blue" |
46 | | - plot_hist('./data/exp.txt', colour='blue') |
47 | | - print "*"*80 |
| 58 | + print "plot_hist('%s', colour='blue')" % demo_file |
| 59 | + print "hist -f %s -c blue" % demo_file |
| 60 | + plot_hist(demo_file, colour='blue') |
| 61 | + print "*" * 80 |
| 62 | + |
48 | 63 | #changing the shape of the point |
49 | 64 | print "changing the shape of the bars" |
50 | | - print "plot_hist('./data/exp.txt', pch='.')" |
51 | | - print "hist -f ./data/exp.txt -p ." |
52 | | - plot_hist('./data/exp.txt', pch='.') |
53 | | - print "*"*80 |
| 65 | + print "plot_hist('%s', pch='.')" % demo_file |
| 66 | + print "hist -f %s -p ." % demo_file |
| 67 | + plot_hist(demo_file, pch='.') |
| 68 | + print "*" * 80 |
| 69 | + |
54 | 70 | #changing the size of the plot |
55 | 71 | print "changing the size of the plot" |
56 | | - print "plot_hist('./data/exp.txt', height=35.0, bincount=40)" |
57 | | - print "hist -f ./data/exp.txt -s 35.0 -b 40" |
58 | | - plot_hist('./data/exp.txt', height=35.0, bincount=40) |
| 72 | + print "plot_hist('%s', height=35.0, bincount=40)" % demo_file |
| 73 | + print "hist -f %s -s 35.0 -b 40" % demo_file |
| 74 | + plot_hist(demo_file, height=35.0, bincount=40) |
| 75 | + |
59 | 76 |
|
60 | 77 | def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="white", title="", xlab=None, showSummary=False, regular=False): |
61 | 78 | """make a histogram |
|
0 commit comments