Skip to content

Commit 24ad106

Browse files
committed
[OSAB] Build scatterplot string, then print it all at once
1 parent cded03a commit 24ad106

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bashplotlib/scatterplot.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ def get_scale(series, is_y=False, steps=20):
3131
def _plot_scatter(xs, ys, size, pch, colour, title, cs):
3232
plotted = set()
3333

34+
plot_str = ""
35+
3436
if title:
35-
print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1)))
37+
plot_str += box_text(title, 2 * (len(get_scale(xs, False, size)) + 1))
3638

37-
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))
39+
plot_str += "-" * (2 * (len(get_scale(xs, False, size)) + 2))
3840
for y in get_scale(ys, True, size):
39-
print("|", end=' ')
41+
plot_str += "|"
4042
for x in get_scale(xs, False, size):
4143
point = " "
4244
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
@@ -46,8 +48,10 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs):
4648
if cs:
4749
colour = cs[i]
4850
printcolour(point + " ", True, colour)
49-
print(" |")
50-
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))
51+
plot_str += " |"
52+
53+
plot_str += "-" * (2 * (len(get_scale(xs, False, size)) + 2))
54+
return plot_str
5155

5256
def plot_scatter(f, xs, ys, size, pch, colour, title):
5357
"""
@@ -81,7 +85,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
8185
with open(ys) as fh:
8286
ys = [float(str(row).strip()) for row in fh]
8387

84-
_plot_scatter(xs, ys, size, pch, colour, title, cs)
88+
print _plot_scatter(xs, ys, size, pch, colour, title, cs)
8589

8690

8791

0 commit comments

Comments
 (0)