Pick event and annotate

Hi all,

How can I combine onpick events with annotate ?
Any pointer would be appreciated.

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('click on points')

line, = ax.plot(np.random.rand(100), 'o', picker=5) # 5 points tolerance

def onpick(event):
     thisline = event.artist
     xdata = thisline.get_xdata()
     ydata = thisline.get_ydata()
     ind = event.ind
     print 'onpick points:', zip(xdata[ind], ydata[ind]), ind
     ax.annotate('Test',xy=(ind, ydata[ind]),horizontalalignment='left',verticalalignment='top')
# ax.redraw_in_frame()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

Thanks in advance.

                          Nils

Hi all,

How can I combine onpick events with annotate ?
Any pointer would be appreciated.

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('click on points')

line, = ax.plot(np.random.rand(100), 'o', picker=5) # 5
points tolerance

def onpick(event):
thisline = event.artist
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()
ind = event.ind
print 'onpick points:', zip(xdata[ind], ydata[ind]),
ind
ax.annotate('Test',xy=(ind,
ydata[ind]),horizontalalignment='left',verticalalignment='top')
# ax.redraw_in_frame()

You need to call fig.canvas.draw() at the end of onpick.

JDH

···

On Wed, Feb 10, 2010 at 4:43 AM, Nils Wagner <nwagner@...1052...> wrote:

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

Thanks in advance.

                     Nils

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options