pylab.plot(...) can overlay a horizontal or vertical line given coordinates
import pylab as pl
import numpy as np
observations = [0.797, 1.116, 1.071, 0.998, -0.333, 1.129, 0.381, 0.815, 1.28715,
0.727, 1.309147, 2.492, 0.946, 0.486536, 0.382539, -0.482, -0.208923,
0.981166, 0.499, 0.022, 0.747333, -0.045, 0.27304, -1.386, 0.654258,
-0.43931, -2.012764, -0.387, -0.730, 0.812032, -0.229, -0.286, -0.293,
-0.483649, 0.232185, -0.027, 0.142, 0.173, -0.618, 0.393, 0.534, 0.804,
-0.867, 0.776, 0.342, 0.797, 0.550, -0.215, 0.706, -0.973]
targets = [-0.007, -0.029, -0.025, -0.0119, -0.0719, -0.1283, -0.1077, -0.0844,
-0.0474, -0.0419, -0.016, 0.0613, 0.0949, 0.0553, 0.0353, 0.0173, 0.0467,
0.0562, 0.0523, -0.0032, 0.0548, 0.0245, 0.0372, 0.0404, 0.0388, 0.0703,
0.0203, -0.0078, -0.0102, 0.0151, -0.0048, -0.0027, 0.0215, -0.0063, -0.0216,
-0.0618, -0.0172, 0.0212, -0.0203, -0.006, 0.0438, 0.0642, 0.0365, 0.0124,
-0.0332, -0.064, 0.0061, -0.0007, -0.0242, -0.036]
#scatter plot using x and y points. c stands for color. s stands for size
pl.scatter(observations, targets, c='red', s=5.5)
max_feature_float = max(observations)
horizontal_line_start_position = 0
num_dots_on_horizontal_line = 20
xs = np.linspace(horizontal_line_start_position,max_feature_float,
num_dots_on_horizontal_line)
horiz_line_data = np.array([0 for i in range(len(xs))])
pl.plot(xs, horiz_line_data, 'b--')
max_tars_float = max(targets)
#make a vertical green line starting at (x=0,y=0) and going to (x=0, y=2) )
pl.plot((0, 0), (0, max_tars_float), 'g-')
#define the feature and targets axis legend names and title.
pl.xlabel("observation")
pl.ylabel("target")
pl.title('Scatterplot of target against observation.')
pl.show()
