@@ -1537,22 +1537,19 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
15371537 else :
15381538 axes_list = [self .canvas .mouse_grabber ]
15391539
1540- if axes_list : # Use highest zorder.
1541- self .inaxes = max (axes_list , key = lambda x : x .zorder )
1542- else : # None found.
1543- self .inaxes = None
1544- self ._update_enter_leave ()
1545- return
1546-
1547- try :
1548- trans = self .inaxes .transData .inverted ()
1549- xdata , ydata = trans .transform_point ((x , y ))
1550- except ValueError :
1551- self .xdata = None
1552- self .ydata = None
1540+ if axes_list :
1541+ self .inaxes = cbook ._topmost_artist (axes_list )
1542+ try :
1543+ trans = self .inaxes .transData .inverted ()
1544+ xdata , ydata = trans .transform_point ((x , y ))
1545+ except ValueError :
1546+ self .xdata = None
1547+ self .ydata = None
1548+ else :
1549+ self .xdata = xdata
1550+ self .ydata = ydata
15531551 else :
1554- self .xdata = xdata
1555- self .ydata = ydata
1552+ self .inaxes = None
15561553
15571554 self ._update_enter_leave ()
15581555
@@ -1815,7 +1812,7 @@ def onRemove(self, ev):
18151812 canvas.mpl_connect('mouse_press_event',canvas.onRemove)
18161813 """
18171814 # Find the top artist under the cursor
1818- under = sorted (self .figure .hitlist (ev ), key = lambda x : x . zorder )
1815+ under = cbook . _topmost_artist (self .figure .hitlist (ev ))
18191816 h = None
18201817 if under :
18211818 h = under [- 1 ]
@@ -2899,7 +2896,7 @@ def mouse_move(self, event):
28992896 if a .contains (event ) and a .get_visible ()]
29002897
29012898 if artists :
2902- a = max (artists , key = lambda x : x . zorder )
2899+ a = cbook . _topmost_artist (artists )
29032900 if a is not event .inaxes .patch :
29042901 data = a .get_cursor_data (event )
29052902 if data is not None :
0 commit comments