Skip to content

Commit bc94e99

Browse files
committed
Using points
1 parent 0386d56 commit bc94e99

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

bashplotlib/scatterplot.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
Plotting terminal based scatterplots
66
"""
77

8-
import csv
98
import sys
109
import optparse
11-
from .utils.helpers import *
10+
from .utils.helpers import (drange,
11+
box_text,
12+
printcolour,
13+
colour_help)
1214
from .utils.commandhelp import scatter
1315

1416

@@ -26,30 +28,23 @@ def get_scale(series, is_y=False, steps=20):
2628
return scaled_series
2729

2830

29-
def plot_scatter(f, xs, ys, size, pch, colour, title):
31+
def plot_scatter(points,
32+
size,
33+
pch,
34+
colour='white',
35+
title='Plot1'):
3036
"""
3137
Form a complex number.
3238
3339
Arguments:
34-
f -- comma delimited file w/ x,y coordinates
35-
xs -- if f not specified this is a file w/ x coordinates
36-
ys -- if f not specified this is a filew / y coordinates
40+
points -- iterable containing (x, y) coordinate pairs
3741
size -- size of the plot
3842
pch -- shape of the points (any character)
3943
colour -- colour of the points
4044
title -- title of the plot
4145
"""
42-
43-
if f:
44-
if isinstance(f, str):
45-
f = open(f)
46-
47-
data = [tuple(map(float, line.strip().split(','))) for line in f]
48-
xs = [i[0] for i in data]
49-
ys = [i[1] for i in data]
50-
else:
51-
xs = [float(str(row).strip()) for row in open(xs)]
52-
ys = [float(str(row).strip()) for row in open(ys)]
46+
xs = [point[0] for point in points]
47+
ys = [point[1] for point in points]
5348

5449
plotted = set()
5550

@@ -61,10 +56,9 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
6156
print "|",
6257
for x in get_scale(xs, False, size):
6358
point = " "
64-
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
59+
for xp, yp in zip(xs, ys):
6560
if xp <= x and yp >= y and (xp, yp) not in plotted:
6661
point = pch
67-
#point = str(i)
6862
plotted.add((xp, yp))
6963
if x==0 and y==0:
7064
point = "o"
@@ -76,7 +70,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
7670
print "|"
7771
print "-"*(2*len(get_scale(xs, False, size))+2)
7872

79-
8073
def main():
8174

8275
parser = optparse.OptionParser(usage=scatter['usage'])

0 commit comments

Comments
 (0)