How to get properties of selected object in mplot3d (matplotlib + python)?

I draw a series of points using mplo3d:

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 add a select function:

 def onpick(event): ind = event.ind print ind fig.canvas.mpl_connect('pick_event', onpick) 

and finally write it down:

 p.show() 

Is there a way to get the 3D coordinates from the marker that I click? So far I can get the index of the point in the list, which I used in ax.scatter (), but which will not cut, since I use ax.scatter many times, and it should be that way (for example, I use different colors)

Hi

+6
source share
1 answer

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

 def onpick(event): ind = event.ind[0] x, y, z = event.artist._offsets3d print x[ind], y[ind], z[ind] 
+8
source

Source: https://habr.com/ru/post/914770/


All Articles