Skip to content

Commit edb0c74

Browse files
committed
Merge pull request glamp#16 from iiSeymour/master
Switched to using entry_points
2 parents 06ba16f + ea272f0 commit edb0c74

File tree

7 files changed

+90
-124
lines changed

7 files changed

+90
-124
lines changed

bashplotlib/histogram.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
import math
34
import optparse
5+
import os
6+
from os.path import dirname
47
import sys
58
from utils.helpers import *
69
from utils.commandhelp import hist
@@ -29,32 +32,47 @@ def read_numbers(numbers):
2932
for n in open(numbers):
3033
yield float(n.strip())
3134

35+
3236
def run_demo():
33-
"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+
3448
#plotting a histogram
3549
print "plotting a basic histogram"
36-
print "plot_hist('./data/exp.txt')"
37-
print "hist -f ./data/exp.txt"
38-
print "cat ./data/exp.txt | hist"
39-
plot_hist('./data/exp.txt')
40-
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+
4156
#with colors
4257
print "histogram with colors"
43-
print "plot_hist('./data/exp.txt', colour='blue')"
44-
print "hist -f ./data/exp.txt -c blue"
45-
plot_hist('./data/exp.txt', colour='blue')
46-
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+
4763
#changing the shape of the point
4864
print "changing the shape of the bars"
49-
print "plot_hist('./data/exp.txt', pch='.')"
50-
print "hist -f ./data/exp.txt -p ."
51-
plot_hist('./data/exp.txt', pch='.')
52-
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+
5370
#changing the size of the plot
5471
print "changing the size of the plot"
55-
print "plot_hist('./data/exp.txt', height=35.0, bincount=40)"
56-
print "hist -f ./data/exp.txt -s 35.0 -b 40"
57-
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+
5876

5977
def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="white", title="", xlab=None, showSummary=False, regular=False):
6078
"""make a histogram
@@ -171,7 +189,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
171189
print summary
172190

173191

174-
if __name__=="__main__":
192+
def main():
175193

176194
parser = optparse.OptionParser(usage=hist['usage'])
177195

@@ -208,3 +226,6 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
208226
else:
209227
print "nothing to plot!"
210228

229+
230+
if __name__=="__main__":
231+
main()

bashplotlib/scatterplot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
import csv
34
import optparse
45
import sys
@@ -71,7 +72,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
7172
print "-"*(2*len(get_scale(xs, False, size))+2)
7273

7374

74-
if __name__=="__main__":
75+
def main():
7576

7677
parser = optparse.OptionParser(usage=scatter['usage'])
7778
parser.add_option('-f', '--file', help='a csv w/ x and y coordinates',
@@ -99,3 +100,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
99100
else:
100101
print "nothing to plot!"
101102

103+
104+
if __name__=="__main__":
105+
main()

bin/hist

Lines changed: 0 additions & 39 deletions
This file was deleted.

bin/scatter

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/downloaddata.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
mkdir data
2-
cd data
3-
curl https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1 > million.txt
4-
curl https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1 > exp.txt
5-
curl https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1 > lower48.txt
6-
curl https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1 > texas.txt
7-
curl https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1 > x_test.txt
8-
curl https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1 > y_test.txt
1+
#!/usr/bin/env bash
92

3+
dir=$(dirname "$0")
4+
5+
if [ ! -d "${dir}data" ]; then
6+
mkdir "${dir}/data"
7+
fi
8+
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"

examples/sample.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
echo plotting coordinates
1+
#!/usr/bin/env bash
22

3-
scatter --file ./data/texas.txt
3+
dir=$(dirname "$0")
44

5-
echo with x and y coords
6-
scatter -x ./data/x_test.txt -y ./data/y_test.txt
5+
if [ ! -d "${dir}/data" ]; then
6+
echo 'downloading data'
7+
"${dir}/downloaddata.sh"
8+
fi
79

8-
echo plotting a histogram
9-
hist --file ./data/exp.txt
10+
echo 'plotting coordinates'
11+
scatter --file "${dir}/data/texas.txt"
1012

11-
echo with colors
12-
hist --file ./data/exp.txt --colour blue
13+
echo 'with x and y coords'
14+
scatter -x "${dir}/data/x_test.txt" -y "${dir}/data/y_test.txt"
1315

14-
echo changing the shape of the point
15-
hist --file ./data/exp.txt --pch .
16+
echo 'plotting a histogram'
17+
hist --file "${dir}/data/exp.txt"
1618

17-
echo using stdin
18-
curl https://dl.dropbox.com/u/49171662/example.txt | hist
19+
echo 'with colors'
20+
hist --file "${dir}/data/exp.txt" --colour blue
1921

20-
echo getting data from a webpage
21-
curl http://www.baseball-reference.com/ \
22-
| grep -o -E "[$]([0-9]+)" | grep -o -E "[0-9]+" \
23-
| hist -b 20 -t "Baseball Payrolls" --height 20 --pch "*"
22+
echo 'changing the shape of the point'
23+
hist --file "${dir}/data/exp.txt" --pch .
2424

25+
#echo 'using stdin'
26+
#curl -sL https://dl.dropbox.com/u/49171662/example.txt | hist
2527

28+
#echo 'getting data from a webpage'
29+
#curl -s 'http://www.baseball-reference.com' |
30+
#grep -o -E '[$][0-9]+' | grep -o -E '[0-9]+' |
31+
#hist -b 20 -t 'Baseball Payrolls' --height 20 --pch '*'

setup.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from distutils.core import setup
2-
from setuptools import find_packages
1+
#!/usr/bin/env python
2+
3+
from setuptools import find_packages, setup
34

45
setup(
56
name="bashplotlib",
@@ -11,6 +12,11 @@
1112
packages=find_packages(),
1213
description="plotting in the terminal",
1314
long_description=open("README.md").read(),
14-
scripts=['bin/hist', 'bin/scatter'],
15+
entry_points = {
16+
'console_scripts': [
17+
'hist=bashplotlib.histogram:main',
18+
'scatter=bashplotlib.scatterplot:main',
19+
]
20+
}
1521
)
1622

0 commit comments

Comments
 (0)