From bf55cbc11395fff0e3d413d8c4f56130d2f8b1c2 Mon Sep 17 00:00:00 2001 From: mixx99 Date: Fri, 9 May 2025 09:50:46 +0300 Subject: [PATCH 1/4] first task --- app.py | 18 ++++++++++++++++++ bashplotlib/utils/helpers.py | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..b58d36c --- /dev/null +++ b/app.py @@ -0,0 +1,18 @@ +# scratch.py +from bashplotlib.scatterplot import plot_scatter + +x_coords = [-10,20,30] +y_coords = [-10,20,30] +width = 10 +char = 'x' +color = 'default' +title = 'My Test Graph' + +plot_scatter( + None, + x_coords, + y_coords, + width, + char, + color, + title) \ No newline at end of file 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 From a360ec684bafa8b419dccafd2287516135ed7426 Mon Sep 17 00:00:00 2001 From: mixx99 Date: Fri, 9 May 2025 10:10:57 +0300 Subject: [PATCH 2/4] task 2 --- bashplotlib/scatterplot.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 69cab9d..eba385b 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): @@ -47,7 +45,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs): colour = cs[i] 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): """ From ce79b682587f9ee80f8f73b43c4a67729262ca7a Mon Sep 17 00:00:00 2001 From: mixx99 Date: Fri, 9 May 2025 10:38:54 +0300 Subject: [PATCH 3/4] task 3 --- bashplotlib/scatterplot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index eba385b..fab0706 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -43,7 +43,16 @@ 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)) - 2) + "+") From 6cd2c7e05c89e01f9dc6d084118c79e13c0cbaf8 Mon Sep 17 00:00:00 2001 From: mixx99 Date: Fri, 9 May 2025 11:39:00 +0300 Subject: [PATCH 4/4] task 4 --- app.py | 12 +++++++----- bashplotlib/histogram.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index b58d36c..44bcb2c 100644 --- a/app.py +++ b/app.py @@ -1,18 +1,20 @@ # scratch.py from bashplotlib.scatterplot import plot_scatter +from bashplotlib.histogram import plot_hist -x_coords = [-10,20,30] -y_coords = [-10,20,30] -width = 10 +x_coords = [0,20,30, 5] +y_coords = [-10,20,30, 0] +width = 20 char = 'x' color = 'default' title = 'My Test Graph' -plot_scatter( +print(plot_scatter( None, x_coords, y_coords, width, char, color, - title) \ No newline at end of file + 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))