有没有办法检测鼠标所关注的matplotlib对象? 这段代码说明了我想要的东西
self.canvas.mpl_connect("motion_notify_event", self.on_focus)
def on_focus(self, event):
# get mouse position in figure
figPos = (event.x,event.y)
# get mouse position in axes if focusing on an axes
axesPos = event.xdata, event.ydata
# get axes instance if mouse is focusing on an axes
axes = event.inaxes
# get object (any matplotlib object, Text, Box, ...) mouse is focused on
obj = event.??????
感谢
答案 0 :(得分:1)
尝试Axes.hitlist
:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(10),range(10))
def on_focus(event):
print ax.hitlist(event)
fig.canvas.mpl_connect("motion_notify_event", on_focus)
plt.show()
但如果您只想要突出显示,则可以使用内置:
fig.canvas.mpl_connect("motion_notify_event",fig.canvas.onHilite)