>>>>> "Jeff" == Jeff Peery <[EMAIL PROTECTED]> writes:

    Jeff> hello, I'm using matplotlib and the wxAgg as a backend with
    Jeff> wxpython for a statistical process control application. I
    Jeff> would like to be able to pick points on an xy line and get
    Jeff> 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.axes.figure.canvas.mpl_connect('button_press_event',
    self.pick)
        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))
        self.callback(ind)

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)
show()


    Jeff> I am also a bit confused as to how pylab is related to
    Jeff> matplotlib. I was informed not to use pylab if using a
    Jeff> backend and wxpython application, so I am only using
    Jeff> matplotlib. Is there a similar bind function to use for
    Jeff> 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.

JDH

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to