Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions bashplotlib/histogram.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/python
#!/usr/bin/env python

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 @@ -29,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 Expand Up @@ -171,7 +189,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="whi
print summary


if __name__=="__main__":
def main():

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

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


if __name__=="__main__":
main()
8 changes: 6 additions & 2 deletions bashplotlib/scatterplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

import csv
import optparse
import sys
Expand Down Expand Up @@ -71,7 +72,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
print "-"*(2*len(get_scale(xs, False, size))+2)


if __name__=="__main__":
def main():

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


if __name__=="__main__":
main()
39 changes: 0 additions & 39 deletions bin/hist

This file was deleted.

37 changes: 0 additions & 37 deletions bin/scatter

This file was deleted.

21 changes: 13 additions & 8 deletions examples/downloaddata.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
mkdir data
cd data
curl https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1 > million.txt
curl https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1 > exp.txt
curl https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1 > lower48.txt
curl https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1 > texas.txt
curl https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1 > x_test.txt
curl https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1 > y_test.txt
#!/usr/bin/env bash

dir=$(dirname "$0")

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

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"
38 changes: 22 additions & 16 deletions examples/sample.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
echo plotting coordinates
#!/usr/bin/env bash

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

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

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

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

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

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

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

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

#echo 'getting data from a webpage'
#curl -s 'http://www.baseball-reference.com' |
#grep -o -E '[$][0-9]+' | grep -o -E '[0-9]+' |
#hist -b 20 -t 'Baseball Payrolls' --height 20 --pch '*'
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from distutils.core import setup
from setuptools import find_packages
#!/usr/bin/env python

from setuptools import find_packages, setup

setup(
name="bashplotlib",
Expand All @@ -11,6 +12,11 @@
packages=find_packages(),
description="plotting in the terminal",
long_description=open("README.md").read(),
scripts=['bin/hist', 'bin/scatter'],
entry_points = {
'console_scripts': [
'hist=bashplotlib.histogram:main',
'scatter=bashplotlib.scatterplot:main',
]
}
)