@@ -28,6 +28,27 @@ def get_scale(series, is_y=False, steps=20):
2828 return scaled_series
2929
3030
31+ def _plot_scatter (xs , ys , size , pch , colour , title , cs ):
32+ plotted = set ()
33+
34+ if title :
35+ print (box_text (title , 2 * len (get_scale (xs , False , size )) + 1 ))
36+
37+ print ("-" * (2 * len (get_scale (xs , False , size )) + 2 ))
38+ for y in get_scale (ys , True , size ):
39+ print ("|" , end = ' ' )
40+ for x in get_scale (xs , False , size ):
41+ point = " "
42+ for (i , (xp , yp )) in enumerate (zip (xs , ys )):
43+ if xp <= x and yp >= y and (xp , yp ) not in plotted :
44+ point = pch
45+ plotted .add ((xp , yp ))
46+ if cs :
47+ colour = cs [i ]
48+ printcolour (point , True , colour )
49+ print (" |" )
50+ print ("-" * (2 * len (get_scale (xs , False , size )) + 2 ))
51+
3152def plot_scatter (f , xs , ys , size , pch , colour , title ):
3253 """
3354 Form a complex number.
@@ -41,7 +62,6 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
4162 colour -- colour of the points
4263 title -- title of the plot
4364 """
44-
4565 cs = None
4666 if f :
4767 if isinstance (f , str ):
@@ -53,31 +73,16 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
5373 ys = [float (i [1 ]) for i in data ]
5474 if len (data [0 ]) > 2 :
5575 cs = [i [2 ].strip () for i in data ]
76+ elif isinstance (xs , list ) and isinstance (ys , list ):
77+ pass
5678 else :
5779 with open (xs ) as fh :
5880 xs = [float (str (row ).strip ()) for row in fh ]
5981 with open (ys ) as fh :
6082 ys = [float (str (row ).strip ()) for row in fh ]
6183
62- plotted = set ()
63-
64- if title :
65- print (box_text (title , 2 * len (get_scale (xs , False , size )) + 1 ))
66-
67- print ("-" * (2 * len (get_scale (xs , False , size )) + 2 ))
68- for y in get_scale (ys , True , size ):
69- print ("|" , end = ' ' )
70- for x in get_scale (xs , False , size ):
71- point = " "
72- for (i , (xp , yp )) in enumerate (zip (xs , ys )):
73- if xp <= x and yp >= y and (xp , yp ) not in plotted :
74- point = pch
75- plotted .add ((xp , yp ))
76- if cs :
77- colour = cs [i ]
78- printcolour (point , True , colour )
79- print (" |" )
80- print ("-" * (2 * len (get_scale (xs , False , size )) + 2 ))
84+ _plot_scatter (xs , ys , size , pch , colour , title , cs )
85+
8186
8287
8388def main ():
0 commit comments