我有一个散点图,并通过 matplotlib http://matplotlib.org/users/transforms_tutorial.html#axes-coordinates实现了一个荧光笔类型的东西。
目前,当您单击任何点时,荧光笔会出现在同一位置,但我想要做的是,当您单击某个点时,它会从该点获取坐标并突出显示该点所在的位置。我的代码是这个
def onclick
ind = event.ind
# the x coords of this transformation are data, and the
# y coord are axes
trans = transforms.blended_transform_factory(
ax.transData, ax.transAxes)
# highlight the 1..2 stddev region with a span.
# We want x to be in data coordinates and y to
# span from 0..1 in axes coords
rect = patches.Rectangle((1,0), width=1, height=1,
transform=trans, color='yellow',
alpha=0.5)
ax.add_patch(rect)
print ('on pick scatter:' , ind , np.take(x,ind), np.take(y,ind))