Skip to content

Commit 6f2c21f

Browse files
author
Director of Analytics
committed
adding command line parsing
1 parent f277b39 commit 6f2c21f

File tree

1 file changed

+55
-37
lines changed

1 file changed

+55
-37
lines changed

bin/scatter.py

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import csv
2+
import optparse
3+
24

35
def drange(start, stop, step=1.0):
46
"generate between 2 numbers w/ optional step"
@@ -20,44 +22,60 @@ def get_scale(series, is_y=False, steps=20):
2022
scaled_series.reverse()
2123
return scaled_series
2224

25+
def plot_scatter(f, xs, ys, size, pch):
26+
if f:
27+
data = [tuple(map(float, line)) for line in csv.reader(open(f))]
28+
xs = [i[0] for i in data]
29+
ys = [i[1] for i in data]
30+
else:
31+
xs = [float(row.strip()) for row in open(xs)]
32+
ys = [float(row.strip()) for row in open(ys)]
33+
34+
plotted = set()
35+
36+
print "-"*(2*len(get_scale(xs, False, size))+2)
37+
for y in get_scale(ys, True, size):
38+
print "|",
39+
for x in get_scale(xs, False, size):
40+
point = " "
41+
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
42+
if xp <= x and yp >= y and (xp, yp) not in plotted:
43+
point = pch
44+
#point = str(i)
45+
plotted.add((xp, yp))
46+
if x==0 and y==0:
47+
point = "o"
48+
elif x==0:
49+
point = "|"
50+
elif y==0:
51+
point = "-"
52+
print point,
53+
print "|"
54+
print "-"*(2*len(get_scale(xs, False, size))+2)
55+
56+
57+
if __name__=="__main__":
58+
59+
parser = optparse.OptionParser()
60+
parser.add_option('-f', '--file', help='a csv w/ x and y coordinates',
61+
default=None, dest='f')
62+
parser.add_option('-x', help='x coordinates',
63+
default=None, dest='x')
64+
parser.add_option('-y', help='y coordinates',
65+
default=None, dest='y')
66+
parser.add_option('-s', '--size',help='y coordinates',
67+
default=20, dest='size', type='int')
68+
parser.add_option('-p', '--pch',help='shape of point',
69+
default="x", dest='pch')
70+
71+
72+
(opts, args) = parser.parse_args()
73+
74+
plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch)
2375

24-
f = "test.txt"
25-
f = "bigtest.txt"
26-
f = "coords.txt"
27-
f = "texas.txt"
28-
29-
if f:
30-
data = [tuple(map(float, line)) for line in csv.reader(open(f))]
31-
else:
32-
xs = xs
33-
ys = ys
34-
xs = [i[0] for i in data]
35-
ys = [i[1] for i in data]
36-
37-
size = 20
38-
39-
plotted = set()
40-
41-
print "-"*(2*len(get_scale(xs, False, size))+2)
42-
for y in get_scale(ys, True, size):
43-
print "|",
44-
for x in get_scale(xs, False, size):
45-
point = " "
46-
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
47-
if xp <= x and yp >= y and (xp, yp) not in plotted:
48-
point = "x"
49-
#point = str(i)
50-
plotted.add((xp, yp))
51-
if x==0 and y==0:
52-
point = "o"
53-
elif x==0:
54-
point = "|"
55-
elif y==0:
56-
point = "-"
57-
print point,
58-
print "|"
59-
print "-"*(2*len(get_scale(xs, False, size))+2)
60-
76+
#plot_scatter("test.txt")
77+
#plot_scatter("bigtest.txt")
78+
#plot_scatter("texas.txt")
6179

6280

6381

0 commit comments

Comments
 (0)