@@ -28,15 +28,19 @@ 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 ):
31+ def _plot_scatter (xs , ys , size , pch , colour , title , cs , x_title , y_title ):
3232 plotted = set ()
3333
3434 if title :
3535 print (box_text (title , 2 * (len (get_scale (xs , False , size )) + 1 )))
3636
37- print ("-" * (2 * (len (get_scale (xs , False , size )) + 2 )) )
37+ print (" +" + " -" * (2 * (len (get_scale (xs , False , size )) + 2 ) - 2 ) + "+" )
3838 for y in get_scale (ys , True , size ):
39- print ("|" , end = ' ' )
39+ if y_title == "" :
40+ print (" |" , end = ' ' )
41+ else :
42+ print (y_title [:1 ], "|" , end = ' ' )
43+ y_title = y_title [1 :]
4044 for x in get_scale (xs , False , size ):
4145 point = " "
4246 for (i , (xp , yp )) in enumerate (zip (xs , ys )):
@@ -47,9 +51,10 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs):
4751 colour = cs [i ]
4852 printcolour (point + " " , True , colour )
4953 print (" |" )
50- print ("-" * (2 * (len (get_scale (xs , False , size )) + 2 )))
54+ print (" +" + "-" * (2 * (len (get_scale (xs , False , size )) + 2 ) - 2 ) + "+" )
55+ print (" " , x_title )
5156
52- def plot_scatter (f , xs , ys , size , pch , colour , title ):
57+ def plot_scatter (f , xs , ys , size , pch , colour , title , x_title , y_title ):
5358 """
5459 Form a complex number.
5560
@@ -81,7 +86,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
8186 with open (ys ) as fh :
8287 ys = [float (str (row ).strip ()) for row in fh ]
8388
84- _plot_scatter (xs , ys , size , pch , colour , title , cs )
89+ _plot_scatter (xs , ys , size , pch , colour , title , cs , x_title , y_title )
8590
8691
8792
@@ -97,14 +102,16 @@ def main():
97102 parser .add_option ('-p' , '--pch' , help = 'shape of point' , default = "x" , dest = 'pch' )
98103 parser .add_option ('-c' , '--colour' , help = 'colour of the plot (%s)' %
99104 colour_help , default = 'default' , dest = 'colour' )
105+ parser .add_option ('-xt' , '--xtitle' , help = 'title for the x-axis' , default = "y axis" , dest = "x_title" )
106+ parser .add_option ('-yt' , '--ytitle' , help = 'title for the y-axis' , default = "x axis" , dest = "y_title" )
100107
101108 opts , args = parser .parse_args ()
102109
103110 if opts .f is None and (opts .x is None or opts .y is None ):
104111 opts .f = sys .stdin .readlines ()
105112
106113 if opts .f or (opts .x and opts .y ):
107- plot_scatter (opts .f , opts .x , opts .y , opts .size , opts .pch , opts .colour , opts .t )
114+ plot_scatter (opts .f , opts .x , opts .y , opts .size , opts .pch , opts .colour , opts .t , opts . x_title , opts . y_title )
108115 else :
109116 print ("nothing to plot!" )
110117
0 commit comments