From 2c415a4350f03602d6570e34062b90ecd6435b72 Mon Sep 17 00:00:00 2001 From: bhusalsa <156117237+bhusalsa@users.noreply.github.com> Date: Sun, 25 May 2025 13:31:48 -0700 Subject: [PATCH 1/4] Updated the display for the Title --- bashplotlib/utils/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1dd949d09c8c875226ccac4ff1c15a868359bdbf Mon Sep 17 00:00:00 2001 From: bhusalsa <156117237+bhusalsa@users.noreply.github.com> Date: Mon, 26 May 2025 19:06:18 -0700 Subject: [PATCH 2/4] Added code for alignment options for the Title --- bashplotlib/utils/helpers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bashplotlib/utils/helpers.py b/bashplotlib/utils/helpers.py index 9e6492b..bf408d5 100644 --- a/bashplotlib/utils/helpers.py +++ b/bashplotlib/utils/helpers.py @@ -76,11 +76,22 @@ def abbreviate(labels, rfill=' '): return abbrev -def box_text(text, width, offset=0): +def box_text(text, title_align, width, offset=0): """ Return text inside an ascii textbox """ + + if title_align == "right": + text = str.rjust(text, width) + elif title_align == "left": + text = str.ljust(text,width) + else: + text = text.center(width) + + if len(text) > width: + text = text[:width-3] + "..." + box = " " * offset + "+" + "-" * (width) + "+" + "\n" - box += " " * offset + "|" + text.center(width) + "|" + "\n" + box += " " * offset + "|" + text + "|" + "\n" box += " " * offset + "+" + "-" * (width) + "+" return box From 85bc5c7a313e7388c7f80c3d8b670c231fdfe925 Mon Sep 17 00:00:00 2001 From: bhusalsa <156117237+bhusalsa@users.noreply.github.com> Date: Mon, 26 May 2025 19:07:09 -0700 Subject: [PATCH 3/4] Added code for displaying the axis titles which are optional --- bashplotlib/scatterplot.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 69cab9d..ef015d2 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -9,6 +9,9 @@ import csv import sys import optparse +from email.policy import default +from pydoc import describe + from .utils.helpers import * from .utils.commandhelp import scatter @@ -28,13 +31,17 @@ def get_scale(series, is_y=False, steps=20): return scaled_series -def _plot_scatter(xs, ys, size, pch, colour, title, cs): +def _plot_scatter(xs, ys, size, pch, colour, title, title_align, cs, xtitle, ytitle): plotted = set() + width = len(get_scale(xs, False, size)) if title: - print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1))) + print(box_text(title, title_align, 2 * (width + 1))) + + if ytitle: + print("y: " + ytitle) - print("-" * (2 * (len(get_scale(xs, False, size)) + 2))) + print("-" * (2 * (width + 2))) for y in get_scale(ys, True, size): print("|", end=' ') for x in get_scale(xs, False, size): @@ -47,9 +54,12 @@ 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 * (width + 2))) + + if xtitle: + print(str("x: " + xtitle).rjust(width)) -def plot_scatter(f, xs, ys, size, pch, colour, title): +def plot_scatter(f, xs, ys, size, pch, colour, title, title_align="center", xtitle="", ytitle=""): """ Form a complex number. @@ -61,6 +71,9 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): pch -- shape of the points (any character) colour -- colour of the points title -- title of the plot + title_align -- alignment for the title of the plot + xtitle -- title for x-axis + ytitle -- title for y-axis """ cs = None if f: @@ -81,7 +94,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): with open(ys) as fh: ys = [float(str(row).strip()) for row in fh] - _plot_scatter(xs, ys, size, pch, colour, title, cs) + _plot_scatter(xs, ys, size, pch, colour, title, title_align, cs, xtitle, ytitle) @@ -97,6 +110,8 @@ def main(): parser.add_option('-p', '--pch', help='shape of point', default="x", dest='pch') parser.add_option('-c', '--colour', help='colour of the plot (%s)' % colour_help, default='default', dest='colour') + parser.add_option('--xtitle', help='title for x-axis of graph', default='', dest='xtitle') + parser.add_option('--ytitle', help='title for y-axis of graph', default='', dest='ytitle') opts, args = parser.parse_args() From 29145d76671ef0847034475df4f4f3692b62edb0 Mon Sep 17 00:00:00 2001 From: bhusalsa <156117237+bhusalsa@users.noreply.github.com> Date: Sat, 31 May 2025 17:33:48 -0700 Subject: [PATCH 4/4] Added code for displaying the 0-axes --- bashplotlib/scatterplot.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index ef015d2..8e3b313 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -34,6 +34,7 @@ def get_scale(series, is_y=False, steps=20): def _plot_scatter(xs, ys, size, pch, colour, title, title_align, cs, xtitle, ytitle): plotted = set() width = len(get_scale(xs, False, size)) + xscale = get_scale(xs,False,size) if title: print(box_text(title, title_align, 2 * (width + 1))) @@ -42,17 +43,32 @@ def _plot_scatter(xs, ys, size, pch, colour, title, title_align, cs, xtitle, yti print("y: " + ytitle) print("-" * (2 * (width + 2))) - for y in get_scale(ys, True, size): + for y in get_scale(ys, True, size): #y axis loop print("|", end=' ') - for x in get_scale(xs, False, size): + + for x in get_scale(xs, False, size): #x axis loop 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)) + plotted.add((xp, yp)) # add the point on the graph if cs: colour = cs[i] - printcolour(point + " ", True, colour) + #printcolour(point + " ", True, colour) + + if point == pch: + printcolour(point + " ", True, colour) + else: + if x == 0 and y == 0: + printcolour("o ", True, colour) + elif y == 0: + printcolour("- ", True, colour) + elif x == 0: + printcolour("| ", True, colour) + else: + printcolour(point + " ", True, colour) + + print(" |") print("-" * (2 * (width + 2)))