Skip to content
Merged
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
45 changes: 25 additions & 20 deletions bashplotlib/scatterplot.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,27 @@ def get_scale(series, is_y=False, steps=20):
return scaled_series


def _plot_scatter(xs, ys, size, pch, colour, title, cs):
plotted = set()

if title:
print(box_text(title, 2 * len(get_scale(xs, False, size)) + 1))

print("-" * (2 * len(get_scale(xs, False, size)) + 2))
for y in get_scale(ys, True, size):
print("|", end=' ')
for x in get_scale(xs, False, size):
point = " "
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
if xp <= x and yp >= y and (xp, yp) not in plotted:
point = pch
plotted.add((xp, yp))
if cs:
colour = cs[i]
printcolour(point, True, colour)
print(" |")
print("-" * (2 * len(get_scale(xs, False, size)) + 2))

def plot_scatter(f, xs, ys, size, pch, colour, title):
"""
Form a complex number.
Expand All@@ -41,7 +62,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
colour -- colour of the points
title -- title of the plot
"""

cs = None
if f:
if isinstance(f, str):
Expand All@@ -53,31 +73,16 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
ys = [float(i[1]) for i in data]
if len(data[0]) > 2:
cs = [i[2].strip() for i in data]
elif isinstance(xs, list) and isinstance(ys, list):
pass
else:
with open(xs) as fh:
xs = [float(str(row).strip()) for row in fh]
with open(ys) as fh:
ys = [float(str(row).strip()) for row in fh]

plotted = set()

if title:
print(box_text(title, 2 * len(get_scale(xs, False, size)) + 1))

print("-" * (2 * len(get_scale(xs, False, size)) + 2))
for y in get_scale(ys, True, size):
print("|", end=' ')
for x in get_scale(xs, False, size):
point = " "
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
if xp <= x and yp >= y and (xp, yp) not in plotted:
point = pch
plotted.add((xp, yp))
if cs:
colour = cs[i]
printcolour(point, True, colour)
print(" |")
print("-" * (2 * len(get_scale(xs, False, size)) + 2))
_plot_scatter(xs, ys, size, pch, colour, title, cs)



def main():
Expand Down