Skip to content

Commit 7c4c566

Browse files
committed
Initial commit on adding color support to scatter-plot
This adds a basic version of color support where the color is given as the third column of the csv file
1 parent 1517bf9 commit 7c4c566

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bashplotlib/scatterplot.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
4646
if isinstance(f, str):
4747
f = open(f)
4848

49-
data = [tuple(map(float, line.strip().split(','))) for line in f]
50-
xs = [i[0] for i in data]
51-
ys = [i[1] for i in data]
49+
data = [tuple(line.strip().split(',')) for line in f]
50+
xs = [float(i[0]) for i in data]
51+
ys = [float(i[1]) for i in data]
52+
if len(data[0]) > 2:
53+
cs = [i[2].strip() for i in data]
54+
else:
55+
cs = None
5256
else:
5357
xs = [float(str(row).strip()) for row in open(xs)]
5458
ys = [float(str(row).strip()) for row in open(ys)]
@@ -67,6 +71,8 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
6771
if xp <= x and yp >= y and (xp, yp) not in plotted:
6872
point = pch
6973
plotted.add((xp, yp))
74+
if cs:
75+
colour = cs[i]
7076
printcolour(point, True, colour)
7177
print(" |")
7278
print("-" * (2 * len(get_scale(xs, False, size)) + 2))

0 commit comments

Comments
 (0)