On 2/5/07, Martin Wilson <mp...@bh...> 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()
|