@@ -661,7 +661,8 @@ def contains(self, mouseevent):
661661 # collection on nonlinear transformed coordinates.
662662 # TODO: consider returning image coordinates (shouldn't
663663 # 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 ])
665666 xmin , xmax , ymin , ymax = self .get_extent ()
666667 if xmin > xmax :
667668 xmin , xmax = xmax , xmin
@@ -983,13 +984,14 @@ def get_cursor_data(self, event):
983984 if self .origin == 'upper' :
984985 ymin , ymax = ymax , ymin
985986 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 ])
990992 if any (np .isnan (point )):
991993 return None
992- i , j = point .astype (int )
994+ j , i = point .astype (int )
993995 # Clip the coordinates at array bounds
994996 if not (0 <= i < arr .shape [0 ]) or not (0 <= j < arr .shape [1 ]):
995997 return None
0 commit comments