On 2/5/07, Martin Wilson <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm using matplotlib in a GTK gui canvas with the GTKAgg backend.  I'm
> connecting a mouse click 'button_press_event' to the click function.  If
> I choose print event.x everything works fine.  However I'm after the x
> value in terms of the x-axis not pixels.  When I try print event.xdata I
> get an error message.  Am I making a stupid mistake or is this a bug?

>     self.canvas.connect('button_press_event',self.click)
>
> def click(self,widget,event):
>        print 'you clicked', event.xdata, event.ydata
>        #print 'you clicked', event.x, event.y
>
>
> Traceback (most recent call last):
>  File "./dangerplotpy", line 120, in click
>    print 'you clicked', event.xdata, event.ydata
> AttributeError: xdata

The matplotlib GTKAgg canvas inherits from the gtk drawing area and
thus inherit's its connect method.  You are connecting to GTK's event
handler, not matplotlib's.  Use canvas.mpl_connect instead, as in this
example

from pylab import figure, show

fig = figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])

def click(event):
    if event.inaxes is not None:
        print 'you clicked', event.xdata, event.ydata

fig.canvas.mpl_connect('button_press_event', click)
show()

-------------------------------------------------------------------------
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