99import csv
1010import sys
1111import optparse
12+ import os
1213from .utils .helpers import *
1314from .utils .commandhelp import scatter
1415
@@ -28,27 +29,27 @@ def get_scale(series, is_y=False, steps=20):
2829 return scaled_series
2930
3031
31- def _plot_scatter (xs , ys , size , pch , colour , title , cs ):
32+ def build_scatter (xs , ys , size , pch , colour , title ):
3233 plotted = set ()
3334
3435 plot_str = ""
3536
3637 if title :
3738 plot_str += box_text (title , 2 * (len (get_scale (xs , False , size )) + 1 ))
39+ plot_str += os .linesep
3840
3941 plot_str += "-" * (2 * (len (get_scale (xs , False , size )) + 2 ))
42+ plot_str += os .linesep
4043 for y in get_scale (ys , True , size ):
41- plot_str += "|"
44+ plot_str += "| "
4245 for x in get_scale (xs , False , size ):
4346 point = " "
4447 for (i , (xp , yp )) in enumerate (zip (xs , ys )):
4548 if xp <= x and yp >= y and (xp , yp ) not in plotted :
4649 point = pch
4750 plotted .add ((xp , yp ))
48- if cs :
49- colour = cs [i ]
50- printcolour (point + " " , True , colour )
51- plot_str += " |"
51+ plot_str += buildcolour (point + " " , colour )
52+ plot_str += " |" + os .linesep
5253
5354 plot_str += "-" * (2 * (len (get_scale (xs , False , size )) + 2 ))
5455 return plot_str
@@ -66,7 +67,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
6667 colour -- colour of the points
6768 title -- title of the plot
6869 """
69- cs = None
7070 if f :
7171 if isinstance (f , str ):
7272 with open (f ) as fh :
@@ -75,8 +75,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
7575 data = [tuple (line .strip ().split (',' )) for line in f ]
7676 xs = [float (i [0 ]) for i in data ]
7777 ys = [float (i [1 ]) for i in data ]
78- if len (data [0 ]) > 2 :
79- cs = [i [2 ].strip () for i in data ]
8078 elif isinstance (xs , list ) and isinstance (ys , list ):
8179 pass
8280 else :
@@ -85,8 +83,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
8583 with open (ys ) as fh :
8684 ys = [float (str (row ).strip ()) for row in fh ]
8785
88- print _plot_scatter (xs , ys , size , pch , colour , title , cs )
89-
86+ print (build_scatter (xs , ys , size , pch , colour , title ))
9087
9188
9289def main ():
0 commit comments