@@ -660,7 +660,8 @@ def contains(self, mouseevent):
660
660
# collection on nonlinear transformed coordinates.
661
661
# TODO: consider returning image coordinates (shouldn't
662
662
# be too difficult given that the image is rectilinear
663
- x , y = mouseevent .xdata , mouseevent .ydata
663
+ trans = self .get_transform ().inverted ()
664
+ x , y = trans .transform ([mouseevent .x , mouseevent .y ])
664
665
xmin , xmax , ymin , ymax = self .get_extent ()
665
666
if xmin > xmax :
666
667
xmin , xmax = xmax , xmin
@@ -982,13 +983,14 @@ def get_cursor_data(self, event):
982
983
if self .origin == 'upper' :
983
984
ymin , ymax = ymax , ymin
984
985
arr = self .get_array ()
985
- data_extent = Bbox ([[ymin , xmin ], [ymax , xmax ]])
986
- array_extent = Bbox ([[0 , 0 ], arr .shape [:2 ]])
987
- trans = BboxTransform (boxin = data_extent , boxout = array_extent )
988
- point = trans .transform ([event .ydata , event .xdata ])
986
+ data_extent = Bbox ([[xmin , ymin ], [xmax , ymax ]])
987
+ array_extent = Bbox ([[0 , 0 ], [arr .shape [1 ], arr .shape [0 ]]])
988
+ trans = self .get_transform ().inverted ()
989
+ trans += BboxTransform (boxin = data_extent , boxout = array_extent )
990
+ point = trans .transform ([event .x , event .y ])
989
991
if any (np .isnan (point )):
990
992
return None
991
- i , j = point .astype (int )
993
+ j , i = point .astype (int )
992
994
# Clip the coordinates at array bounds
993
995
if not (0 <= i < arr .shape [0 ]) or not (0 <= j < arr .shape [1 ]):
994
996
return None
0 commit comments