8

I plot a series of points using mplot3d:

import pylab as p
import mpl_toolkits.mplot3d.axes3d as p3

fig = p.figure()
ax = fig.add_subplot(111, projection='3d')

ax.scatter([1], [0], [0], c='r', marker='^', picker=5)
ax.scatter([0], [1], [0], c='g', marker='^', picker=5)
ax.scatter([0], [0], [1], c='b', marker='^', picker=5)

and then I add a picker function:

def onpick(event):
   ind = event.ind
   print ind

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

and finally plot it:

p.show()

Is there a way of getting the 3D coordinates from the marker I am clicking? So far I can get the index of the point in the list I used at ax.scatter(), but that wont cut it as I use ax.scatter() many times and this has to be this way (I use different colors for example).

Regards

Trevor
  • 545
  • 4
  • 19
user1371437
  • 81
  • 1
  • 2

1 Answers1

10

You can use _offsets3d attribute of event.artist to get the coordinate data, and then use ind to get the picked point:

def onpick(event):
    ind = event.ind[0]
    x, y, z = event.artist._offsets3d
    print x[ind], y[ind], z[ind]
HYRY
  • 94,853
  • 25
  • 187
  • 187