diff --git a/app.py b/app.py new file mode 100644 index 0000000..44bcb2c --- /dev/null +++ b/app.py @@ -0,0 +1,20 @@ +# scratch.py +from bashplotlib.scatterplot import plot_scatter +from bashplotlib.histogram import plot_hist + +x_coords = [0,20,30, 5] +y_coords = [-10,20,30, 0] +width = 20 +char = 'x' +color = 'default' +title = 'My Test Graph' + +print(plot_scatter( + None, + x_coords, + y_coords, + width, + char, + color, + title)) +plot_hist(x_coords, 20.0, None, None, "o", "default", title, None, True, False) \ No newline at end of file diff --git a/bashplotlib/histogram.py b/bashplotlib/histogram.py index fe0a5f7..ab3936a 100644 --- a/bashplotlib/histogram.py +++ b/bashplotlib/histogram.py @@ -202,7 +202,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def center += 15 if showSummary: - print() + print("") print("-" * (2 + center)) print("|" + "Summary".center(center) + "|") print("-" * (2 + center)) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 69cab9d..fab0706 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -30,11 +30,9 @@ def get_scale(series, is_y=False, steps=20): 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))) + print("+" + "-" * ((2 * (len(get_scale(xs, False, size)) + 2)) - 2) + "+") for y in get_scale(ys, True, size): print("|", end=' ') for x in get_scale(xs, False, size): @@ -45,9 +43,18 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs): plotted.add((xp, yp)) if cs: colour = cs[i] - printcolour(point + " ", True, colour) + if(point != " "): + printcolour(point + " ", True, colour) + elif(x == 0 and y == 0): + printcolour("0" + " ", True, colour) + elif(x == 0): + printcolour("|" + " ", True, colour) + elif(y == 0): + printcolour("-" + " ", True, colour) + else: + printcolour(point + " ", True, colour) print(" |") - print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) + print("+" + "-" * ((2 * (len(get_scale(xs, False, size)) + 2)) - 2) + "+") def plot_scatter(f, xs, ys, size, pch, colour, title): """ diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index cf209ee..9e6492b 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -80,7 +80,7 @@ def box_text(text, width, offset=0): """ Return text inside an ascii textbox """ - box = " " * offset + "-" * (width+2) + "\n" + box = " " * offset + "+" + "-" * (width) + "+" + "\n" box += " " * offset + "|" + text.center(width) + "|" + "\n" - box += " " * offset + "-" * (width+2) + box += " " * offset + "+" + "-" * (width) + "+" return box