From bc94e99459512ef348fcb2e514a0c5a798a492c8 Mon Sep 17 00:00:00 2001 From: Kevin Yokley Date: Fri, 3 Jul 2015 13:59:48 -0500 Subject: [PATCH] Using points --- bashplotlib/scatterplot.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/bashplotlib/scatterplot.py b/bashplotlib/scatterplot.py index 23a49fd..83b1488 100644 --- a/bashplotlib/scatterplot.py +++ b/bashplotlib/scatterplot.py @@ -5,10 +5,12 @@ Plotting terminal based scatterplots """ -import csv import sys import optparse -from .utils.helpers import * +from .utils.helpers import (drange, + box_text, + printcolour, + colour_help) from .utils.commandhelp import scatter @@ -26,30 +28,23 @@ def get_scale(series, is_y=False, steps=20): return scaled_series -def plot_scatter(f, xs, ys, size, pch, colour, title): +def plot_scatter(points, + size, + pch, + colour='white', + title='Plot1'): """ Form a complex number. Arguments: - f -- comma delimited file w/ x,y coordinates - xs -- if f not specified this is a file w/ x coordinates - ys -- if f not specified this is a filew / y coordinates + points -- iterable containing (x, y) coordinate pairs size -- size of the plot pch -- shape of the points (any character) colour -- colour of the points title -- title of the plot """ - - if f: - 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] - else: - xs = [float(str(row).strip()) for row in open(xs)] - ys = [float(str(row).strip()) for row in open(ys)] + xs = [point[0] for point in points] + ys = [point[1] for point in points] plotted = set() @@ -61,10 +56,9 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): print "|", for x in get_scale(xs, False, size): point = " " - for (i, (xp, yp)) in enumerate(zip(xs, ys)): + for xp, yp in 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" @@ -76,7 +70,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title): print "|" print "-"*(2*len(get_scale(xs, False, size))+2) - def main(): parser = optparse.OptionParser(usage=scatter['usage'])