@@ -170,16 +170,36 @@ def test_cursor_data():
170170    xdisp , ydisp  =  ax .transData .transform_point ([x , y ])
171171
172172    event  =  MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
173-     assert  im .get_cursor_data (event ) ==  44 
173+     z  =  im .get_cursor_data (event )
174+     assert  z  ==  44 , "Did not get 44, got %d"  %  z 
175+ 
176+     # Now try for a point outside the image 
177+     # Tests issue #4957 
178+     x , y  =  10.1 , 4 
179+     xdisp , ydisp  =  ax .transData .transform_point ([x , y ])
180+ 
181+     event  =  MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
182+     z  =  im .get_cursor_data (event )
183+     assert  z  is  None , "Did not get None, got %d"  %  z 
184+ 
185+     # Hmm, something is wrong here... I get 0, not None... 
186+     # But, this works further down in the tests with extents flipped 
187+     #x, y = 0.1, -0.1 
188+     #xdisp, ydisp = ax.transData.transform_point([x, y]) 
189+     #event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) 
190+     #z = im.get_cursor_data(event) 
191+     #assert z is None, "Did not get None, got %d" % z 
174192
175193    ax .clear ()
194+     # Now try with the extents flipped. 
176195    im  =  ax .imshow (np .arange (100 ).reshape (10 , 10 ), origin = 'lower' )
177196
178197    x , y  =  4 , 4 
179198    xdisp , ydisp  =  ax .transData .transform_point ([x , y ])
180199
181200    event  =  MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
182-     assert  im .get_cursor_data (event ) ==  44 
201+     z  =  im .get_cursor_data (event )
202+     assert  z  ==  44 , "Did not get 44, got %d"  %  z 
183203
184204    fig , ax  =  plt .subplots ()
185205    im  =  ax .imshow (np .arange (100 ).reshape (10 , 10 ), extent = [0 , 0.5 , 0 , 0.5 ])
@@ -188,7 +208,24 @@ def test_cursor_data():
188208    xdisp , ydisp  =  ax .transData .transform_point ([x , y ])
189209
190210    event  =  MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
191-     assert  im .get_cursor_data (event ) ==  55 
211+     z  =  im .get_cursor_data (event )
212+     assert  z  ==  55 , "Did not get 55, got %d"  %  z 
213+ 
214+     # Now try for a point outside the image 
215+     # Tests issue #4957 
216+     x , y  =  0.75 , 0.25 
217+     xdisp , ydisp  =  ax .transData .transform_point ([x , y ])
218+ 
219+     event  =  MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
220+     z  =  im .get_cursor_data (event )
221+     assert  z  is  None , "Did not get None, got %d"  %  z 
222+ 
223+     x , y  =  0.01 , - 0.01 
224+     xdisp , ydisp  =  ax .transData .transform_point ([x , y ])
225+ 
226+     event  =  MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
227+     z  =  im .get_cursor_data (event )
228+     assert  z  is  None , "Did not get None, got %d"  %  z 
192229
193230
194231@image_comparison (baseline_images = ['image_clip' ]) 
0 commit comments