def test_closest_point_axis(): ''' test closest point relative to axis coordinates ''' x = [950, 1000] y = [10, 1] click_x, click_y = 950, 1 line, = plt.plot(x,y) plot = ClickPlot(line) plot.axis.set_xlim(0, 1000) plot.axis.set_ylim(0, 1) index, dist = plot.get_closest_point_axis(click_x, click_y) assert index == 1
def test_closest_point(): ''' ClickPlot.get_closest_point(x,y) should return an index to and the coordinates of the data point closest to (x,y) ''' points = [(0,0), (10,0), (10,10), (0,10)] clicks = [(0,0), (6,6), (5,5)] answers = [(0,0,0), (2,10,10), (0,0,0)] xdata, ydata = [], [] for point in points: xdata.append(point[0]) ydata.append(point[1]) line, = plt.plot(xdata, ydata) plot = ClickPlot(line) for i in range(len(clicks)): click_x, click_y = clicks[i][0], clicks[i][1] ans_index, ans_x, ans_y = answers[i][0], answers[i][1], answers[i][2] index, x, y = plot.get_closest_point(click_x, click_y) print "answer: index, x, y = ", ans_index, ans_x, ans_y print "function: index, x, y = ", index, x, y assert_equal( (index, x, y), (ans_index, ans_x, ans_y))