我有一个由不同调用组成的散点图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()
我希望这些点是可点击的,并获取所选索引的 x,y。
然而自从scatter
被多次调用,我得到相同的索引两次,所以我不能使用x[index]
在 - 的里面onpick3
method
有没有直接获取积分的方法?
看起来event.artist
回馈相同的PathCollection
这是从返回的scatter
(p
and p1
在这种情况下)。
但我找不到任何方法来使用它来提取x,y
所选索引的
尝试使用event.artist.get_paths()
- 但它似乎并没有返回所有的分散点,而是只返回我点击的那个分散点..所以我真的不确定是什么event.artist
正在回馈,什么是回馈event.artist.get_paths()
功能是回馈
EDIT
看起来event.artist._offsets
给出一个具有相关偏移量的数组,但由于某种原因尝试使用时event.artist.offsets
I get
AttributeError: 'PathCollection' object has no attribute 'offsets'
(虽然如果我理解docs http://matplotlib.org/api/collections_api.html?highlight=pathcollection#matplotlib.collections.PathCollection,它应该在那里)