Skip to content

Commit 2464758

Browse files
committed
made testable (_plot_scatter returns string of graph)
1 parent b6d55d6 commit 2464758

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

bashplotlib/scatterplot.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ def get_scale(series, is_y=False, steps=20):
3030

3131
def _plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title):
3232
plotted = set()
33+
graph = ""
3334

3435
if title:
35-
print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1)))
36+
graph += box_text(title, 2 * (len(get_scale(xs, False, size)) + 1)) + '\n'
3637

37-
print(" +" + "-" * (2 * (len(get_scale(xs, False, size)) + 2) - 2) + "+")
38+
graph += " +" + "-" * (2 * (len(get_scale(xs, False, size)) + 2) - 2) + "+\n"
3839
for y in get_scale(ys, True, size):
3940
if y_title == "":
40-
print(" |", end=' ')
41+
graph += " | "
4142
else:
42-
print(y_title[:1], "|", end=' ')
43+
graph += y_title[:1] + " | "
4344
y_title = y_title[1:]
4445
for x in get_scale(xs, False, size):
4546
point = " "
@@ -57,10 +58,11 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title):
5758
point = "|"
5859
elif y == 0.0:
5960
point = "-"
60-
printcolour(point + " ", True, colour)
61-
print(" |")
62-
print(" +" + "-" * (2 * (len(get_scale(xs, False, size)) + 2) - 2) + "+")
63-
print(" ", x_title)
61+
graph += point + " "
62+
graph += " |\n"
63+
graph += " +" + "-" * (2 * (len(get_scale(xs, False, size)) + 2) - 2) + "+"
64+
graph += " " + x_title
65+
return graph
6466

6567
def plot_scatter(f, xs, ys, size, pch, colour, title, x_title, y_title):
6668
"""
@@ -94,7 +96,8 @@ def plot_scatter(f, xs, ys, size, pch, colour, title, x_title, y_title):
9496
with open(ys) as fh:
9597
ys = [float(str(row).strip()) for row in fh]
9698

97-
_plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title)
99+
graph = _plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title)
100+
print(graph)
98101

99102

100103

0 commit comments

Comments
 (0)