From 1517bf98694c55628e864b31e125a2c3831fe411 Mon Sep 17 00:00:00 2001 From: Gregory Ashton Date: Wed, 7 Oct 2015 16:25:53 +0100 Subject: [PATCH 1/2] Improves the setting of xlims in the scatter plot * Fixes a bug in which the right-most data point is not includes by using the `drange` include_stop argument * Removes unneccersery code that is repeating the operation of plotting a border * Add a space between the final data point and the right-hand border --- bashplotlib/scatterplot.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index ddaf3cc..1516bcd 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -17,7 +17,8 @@ def get_scale(series, is_y=False, steps=20): min_val = min(series) max_val = max(series) scaled_series = [] - for x in drange(min_val, max_val, (max_val - min_val) / steps): + for x in drange(min_val, max_val, (max_val - min_val) / steps, + include_stop=True): if x > 0 and scaled_series and max(scaled_series) < 0: scaled_series.append(0.0) scaled_series.append(x) @@ -65,16 +66,9 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): for (i, (xp, yp)) in enumerate(zip(xs, ys)): if xp <= x and yp >= y and (xp, yp) not in plotted: point = pch - #point = str(i) plotted.add((xp, yp)) - if x == 0 and y == 0: - point = "o" - elif x == 0: - point = "|" - elif y == 0: - point = "-" printcolour(point, True, colour) - print("|") + print(" |") print("-" * (2 * len(get_scale(xs, False, size)) + 2)) From 7c4c5664f862c25918679511773af0131b115781 Mon Sep 17 00:00:00 2001 From: Gregory Ashton Date: Wed, 7 Oct 2015 17:14:58 +0100 Subject: [PATCH 2/2] Initial commit on adding color support to scatter-plot This adds a basic version of color support where the color is given as the third column of the csv file --- bashplotlib/scatterplot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 1516bcd..b9a1948 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -46,9 +46,13 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): if isinstance(f, str): f = open(f) - data = [tuple(map(float, line.strip().split(','))) for line in f] - xs = [i[0] for i in data] - ys = [i[1] for i in data] + data = [tuple(line.strip().split(',')) for line in f] + xs = [float(i[0]) for i in data] + ys = [float(i[1]) for i in data] + if len(data[0]) > 2: + cs = [i[2].strip() for i in data] + else: + cs = None else: xs = [float(str(row).strip()) for row in open(xs)] ys = [float(str(row).strip()) for row in open(ys)] @@ -67,6 +71,8 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): if xp <= x and yp >= y and (xp, yp) not in plotted: point = pch plotted.add((xp, yp)) + if cs: + colour = cs[i] printcolour(point, True, colour) print(" |") print("-" * (2 * len(get_scale(xs, False, size)) + 2))