@@ -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,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
4162 colour -- colour of the points
4263 title -- title of the plot
4364 """
44-
65+ cs = None
4566 if f :
4667 if isinstance (f , str ):
4768 f = open (f )
@@ -51,31 +72,14 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
5172 ys = [float (i [1 ]) for i in data ]
5273 if len (data [0 ]) > 2 :
5374 cs = [i [2 ].strip () for i in data ]
54- else :
55- cs = None
75+ elif isinstance ( xs , list ) and isinstance ( ys , list ) :
76+ pass
5677 else :
5778 xs = [float (str (row ).strip ()) for row in open (xs )]
5879 ys = [float (str (row ).strip ()) for row in open (ys )]
5980
60- plotted = set ()
61-
62- if title :
63- print (box_text (title , 2 * len (get_scale (xs , False , size )) + 1 ))
64-
65- print ("-" * (2 * len (get_scale (xs , False , size )) + 2 ))
66- for y in get_scale (ys , True , size ):
67- print ("|" , end = ' ' )
68- for x in get_scale (xs , False , size ):
69- point = " "
70- for (i , (xp , yp )) in enumerate (zip (xs , ys )):
71- if xp <= x and yp >= y and (xp , yp ) not in plotted :
72- point = pch
73- plotted .add ((xp , yp ))
74- if cs :
75- colour = cs [i ]
76- printcolour (point , True , colour )
77- print (" |" )
78- print ("-" * (2 * len (get_scale (xs , False , size )) + 2 ))
81+ _plot_scatter (xs , ys , size , pch , colour , title , cs )
82+
7983
8084
8185def main ():
0 commit comments