2014-01-31 11 views
0

有什麼辦法可以檢測到鼠標關注的matplotlib對象嗎? 這樣的一段代碼,說明了什麼,我想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

你想知道whe ñ鼠標_懸停在對象上或只是在點擊它時? –

+0

基本上當它徘徊...... – Cobry

回答

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)

相關問題