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