picking vertices of a line

hello, I'm using matplotlib and the wxAgg as a backend with

    > wxpython for a statistical process control application. I
    > would like to be able to pick points on an xy line and get
    > the index of the point. I looked at the picker_demo demo and

You could do something like the following (you'll probably want to add
some epsilon condition for closeness)

from pylab import figure, show, nx

class PickVert:
    def __init__(self, axes, line, callback):
        'call callback with the nearest vert picked'
        self.line = line
        self.axes = axes
        self.callback = callback

    def pick(self, event):
        if event.button!=1 or event.inaxes!=self.axes: return
        x = line.get_xdata()
        y = line.get_ydata()
        d = nx.sqrt((event.xdata - x)**2 + (event.ydata-y)**2)
        ind = nx.nonzero(d==nx.amin(d))

def callback(ind):
    print 'the index is', ind

fig = figure()
ax = fig.add_subplot(111)
x = nx.arange(20)
y = nx.mlab.rand(20)
line, = ax.plot(x, y, 'o')

picker = PickVert(ax, line, callback)

    > I am also a bit confused as to how pylab is related to
    > matplotlib. I was informed not to use pylab if using a
    > backend and wxpython application, so I am only using
    > matplotlib. Is there a similar bind function to use for
    > binding the pick event to the callback function? thanks.

pylab is a procedural wrapper of the matplotlib API that does things
for you like manage the creation and destruction of GUI windows and it
works across multiple GUIs. If you are writing a GUI app, you do not
want pylab to manage that for you.