I have a scatter plot that is composed of different calls for scatter:
import matplotlib.pyplot as plt
import numpy as np
def onpick3(event):
index = event.ind
print '--------------'
print index
artist = event.artist
print artist
fig_handle = plt.figure()
x,y = np.random.rand(10),np.random.rand(10)
x1,y1 = np.random.rand(10),np.random.rand(10)
axes_size = 0.1,0.1,0.9,0.9
ax = fig_handle.add_axes(axes_size)
p = ax.scatter (x,y, marker='*', s=60, color='r', picker=True, lw=2)
p1 = ax.scatter (x1,y1, marker='*', s=60, color='b', picker=True, lw=2)
fig_handle.canvas.mpl_connect('pick_event', onpick3)
plt.show()
I'd like the points to be clickable, and get the x,y of the selected indexes.
However since scatter is being called more than once, I get the same indexes twice, so I cant use x[index] inside the onpick3 method
Is there a straightforward way to get the points?
It seems that event.artist gives back the same PathCollection that is given back from scatter (p and p1 in this case).
But I couldn't find any way to use it to extract the x,y of the selected indexes
Tried using event.artist.get_paths() - but it doesn't seem to be giving back all the scatter points, but only the one that I clicked on..so I'm really not sure what event.artist is giving back and what are the event.artist.get_paths() function is giving back
EDIT
it seems that event.artist._offsets gives an array with the relevant offsets, but for some reason when trying to use event.artist.offsetsI get
AttributeError: 'PathCollection' object has no attribute 'offsets'
(although if I understand the docs, it should be there)