| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 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 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,14 @@ | |||
| 1 | 1 | #!/usr/bin/env bash | |
| 2 | 2 | ||
| 3 | - if [ ! -d data ]; then | ||
| 4 | - mkdir data | ||
| 3 | + dir=$(dirname "$0") | ||
| 4 | + | ||
| 5 | + if [ ! -d "${dir}data" ]; then | ||
| 6 | + mkdir "${dir}/data" | ||
| 5 | 7 | fi | |
| 6 | - cd data | ||
| 7 | 8 | ||
| 8 | - curl -L 'https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1' > million.txt | ||
| 9 | - curl -L 'https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1' > exp.txt | ||
| 10 | - curl -L 'https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1' > lower48.txt | ||
| 11 | - curl -L 'https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1' > texas.txt | ||
| 12 | - curl -L 'https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1' > x_test.txt | ||
| 13 | - curl -L 'https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1' > y_test.txt | ||
| 9 | + curl -L 'https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1' > "${dir}/data/million.txt" | ||
| 10 | + curl -L 'https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1' > "${dir}/data/exp.txt" | ||
| 11 | + curl -L 'https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1' > "${dir}/data/lower48.txt" | ||
| 12 | + curl -L 'https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1' > "${dir}/data/texas.txt" | ||
| 13 | + curl -L 'https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1' > "${dir}/data/x_test.txt" | ||
| 14 | + curl -L 'https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1' > "${dir}/data/y_test.txt" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,24 +1,26 @@ | |||
| 1 | 1 | #!/usr/bin/env bash | |
| 2 | 2 | ||
| 3 | - if [ ! -d data ]; then | ||
| 3 | + dir=$(dirname "$0") | ||
| 4 | + | ||
| 5 | + if [ ! -d "${dir}/data" ]; then | ||
| 4 | 6 | echo 'downloading data' | |
| 5 | - ./downloaddata.sh | ||
| 7 | + "${dir}/downloaddata.sh" | ||
| 6 | 8 | fi | |
| 7 | 9 | ||
| 8 | 10 | echo 'plotting coordinates' | |
| 9 | - scatter --file ./data/texas.txt | ||
| 11 | + scatter --file "${dir}/data/texas.txt" | ||
| 10 | 12 | ||
| 11 | 13 | echo 'with x and y coords' | |
| 12 | - scatter -x ./data/x_test.txt -y ./data/y_test.txt | ||
| 14 | + scatter -x "${dir}/data/x_test.txt" -y "${dir}/data/y_test.txt" | ||
| 13 | 15 | ||
| 14 | 16 | echo 'plotting a histogram' | |
| 15 | - hist --file ./data/exp.txt | ||
| 17 | + hist --file "${dir}/data/exp.txt" | ||
| 16 | 18 | ||
| 17 | 19 | echo 'with colors' | |
| 18 | - hist --file ./data/exp.txt --colour blue | ||
| 20 | + hist --file "${dir}/data/exp.txt" --colour blue | ||
| 19 | 21 | ||
| 20 | 22 | echo 'changing the shape of the point' | |
| 21 | - hist --file ./data/exp.txt --pch . | ||
| 23 | + hist --file "${dir}/data/exp.txt" --pch . | ||
| 22 | 24 | ||
| 23 | 25 | #echo 'using stdin' | |
| 24 | 26 | #curl -sL https://dl.dropbox.com/u/49171662/example.txt | hist | |
| Back | FazBrowse Home | New Git URL |
0 commit comments