@@ -28,6 +28,27 @@ def get_scale(series, is_y=False, steps=20):
28
28
return scaled_series
29
29
30
30
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
+
31
52
def plot_scatter (f , xs , ys , size , pch , colour , title ):
32
53
"""
33
54
Form a complex number.
@@ -41,7 +62,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
41
62
colour -- colour of the points
42
63
title -- title of the plot
43
64
"""
44
-
65
+ cs = None
45
66
if f :
46
67
if isinstance (f , str ):
47
68
f = open (f )
@@ -51,31 +72,14 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
51
72
ys = [float (i [1 ]) for i in data ]
52
73
if len (data [0 ]) > 2 :
53
74
cs = [i [2 ].strip () for i in data ]
54
- else :
55
- cs = None
75
+ elif isinstance ( xs , list ) and isinstance ( ys , list ) :
76
+ pass
56
77
else :
57
78
xs = [float (str (row ).strip ()) for row in open (xs )]
58
79
ys = [float (str (row ).strip ()) for row in open (ys )]
59
80
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
+
79
83
80
84
81
85
def main ():
0 commit comments