Getting x, y from a scatter plot with multiple data sets?

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, )

+4
1

x, y , scatter, event.artist.get_offsets() (Matplotlib getters seters . get_offsets - return self._offsets, "".).

, :

import matplotlib.pyplot as plt
import numpy as np

def onpick3(event):
    index = event.ind
    xy = event.artist.get_offsets()
    print '--------------'
    print xy[index]


fig, ax = plt.subplots()

x, y = np.random.random((2, 10))
x1, y1 = np.random.random((2, 10))

p = ax.scatter(x, y, marker='*', s=60, color='r', picker=True)
p1 = ax.scatter(x1, y1, marker='*', s=60, color='b', picker=True)

fig.canvas.mpl_connect('pick_event', onpick3)
plt.show()

, , scatter . plot. scatter , , Line2D, plot. ( plot, x, y = artist.get_data().)

, , mpldatacursor . .

, :

+4

All Articles