I have a scatter plot consisting of different scatter calls:
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 would like the points to be clickable and get the x, y of the selected indices. However, since it scatteris called more than once, I get the same indexes twice, so I cannot use x[index]inside the methodonpick3
Is there an easy way to get points?
, event.artist PathCollection, scatter (p p1).
x,y
event.artist.get_paths() - , , , , . , event.artist event.artist.get_paths()
, event.artist._offsets , - event.artist.offsets
AttributeError: 'PathCollection' object has no attribute 'offsets'
(, docs, )