Skip to content

Commit

Permalink
Fixed the data location and made hist -d gracefully quit if not demo …
Browse files Browse the repository at this point in the history
…file exists
  • Loading branch information
iiSeymour committed May 18, 2014
1 parent 877f667 commit ea272f0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
51 changes: 34 additions & 17 deletions bashplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import math
import optparse
import os
from os.path import dirname
import sys
from utils.helpers import *
from utils.commandhelp import hist
Expand Down Expand Up @@ -30,32 +32,47 @@ def read_numbers(numbers):
for n in open(numbers):
yield float(n.strip())


def run_demo():
"demo the product"
"""
Run a demonstration
"""
module_dir = dirname(dirname(os.path.realpath(__file__)))
demo_file = os.path.join(module_dir, 'examples/data/exp.txt')

if not os.path.isfile(demo_file):
sys.stderr.write("demo input file not found!\n")
sys.stderr.write("run the downloaddata.sh script in the example first\n")
sys.exit(1)

#plotting a histogram
print "plotting a basic histogram"
print "plot_hist('./data/exp.txt')"
print "hist -f ./data/exp.txt"
print "cat ./data/exp.txt | hist"
plot_hist('./data/exp.txt')
print "*"*80
print "plot_hist('%s')" % demo_file
print "hist -f %s" % demo_file
print "cat %s | hist" % demo_file
plot_hist(demo_file)
print "*" * 80

#with colors
print "histogram with colors"
print "plot_hist('./data/exp.txt', colour='blue')"
print "hist -f ./data/exp.txt -c blue"
plot_hist('./data/exp.txt', colour='blue')
print "*"*80
print "plot_hist('%s', colour='blue')" % demo_file
print "hist -f %s -c blue" % demo_file
plot_hist(demo_file, colour='blue')
print "*" * 80

#changing the shape of the point
print "changing the shape of the bars"
print "plot_hist('./data/exp.txt', pch='.')"
print "hist -f ./data/exp.txt -p ."
plot_hist('./data/exp.txt', pch='.')
print "*"*80
print "plot_hist('%s', pch='.')" % demo_file
print "hist -f %s -p ." % demo_file
plot_hist(demo_file, pch='.')
print "*" * 80

#changing the size of the plot
print "changing the size of the plot"
print "plot_hist('./data/exp.txt', height=35.0, bincount=40)"
print "hist -f ./data/exp.txt -s 35.0 -b 40"
plot_hist('./data/exp.txt', height=35.0, bincount=40)
print "plot_hist('%s', height=35.0, bincount=40)" % demo_file
print "hist -f %s -s 35.0 -b 40" % demo_file
plot_hist(demo_file, height=35.0, bincount=40)


def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="white", title="", xlab=None, showSummary=False, regular=False):
"""make a histogram
Expand Down
19 changes: 10 additions & 9 deletions examples/downloaddata.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env bash

if [ ! -d data ]; then
mkdir data
dir=$(dirname "$0")

if [ ! -d "${dir}data" ]; then
mkdir "${dir}/data"
fi
cd data

curl -L 'https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1' > million.txt
curl -L 'https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1' > exp.txt
curl -L 'https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1' > lower48.txt
curl -L 'https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1' > texas.txt
curl -L 'https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1' > x_test.txt
curl -L 'https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1' > y_test.txt
curl -L 'https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1' > "${dir}/data/million.txt"
curl -L 'https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1' > "${dir}/data/exp.txt"
curl -L 'https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1' > "${dir}/data/lower48.txt"
curl -L 'https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1' > "${dir}/data/texas.txt"
curl -L 'https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1' > "${dir}/data/x_test.txt"
curl -L 'https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1' > "${dir}/data/y_test.txt"
16 changes: 9 additions & 7 deletions examples/sample.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/usr/bin/env bash

if [ ! -d data ]; then
dir=$(dirname "$0")

if [ ! -d "${dir}/data" ]; then
echo 'downloading data'
./downloaddata.sh
"${dir}/downloaddata.sh"
fi

echo 'plotting coordinates'
scatter --file ./data/texas.txt
scatter --file "${dir}/data/texas.txt"

echo 'with x and y coords'
scatter -x ./data/x_test.txt -y ./data/y_test.txt
scatter -x "${dir}/data/x_test.txt" -y "${dir}/data/y_test.txt"

echo 'plotting a histogram'
hist --file ./data/exp.txt
hist --file "${dir}/data/exp.txt"

echo 'with colors'
hist --file ./data/exp.txt --colour blue
hist --file "${dir}/data/exp.txt" --colour blue

echo 'changing the shape of the point'
hist --file ./data/exp.txt --pch .
hist --file "${dir}/data/exp.txt" --pch .

#echo 'using stdin'
#curl -sL https://dl.dropbox.com/u/49171662/example.txt | hist
Expand Down

0 comments on commit ea272f0

Please sign in to comment.