@@ -365,6 +365,38 @@ def test_cursor_data():
365365 assert im .get_cursor_data (event ) == 44
366366
367367
368+ @pytest .mark .parametrize ("xy, data" , [
369+ # x/y coords chosen to be 0.5 above boundaries so they lie within image pixels
370+ [[0.5 , 0.5 ], 0 + 0 ],
371+ [[0.5 , 1.5 ], 0 + 1 ],
372+ [[4.5 , 0.5 ], 16 + 0 ],
373+ [[8.5 , 0.5 ], 16 + 0 ],
374+ [[9.5 , 2.5 ], 81 + 4 ],
375+ [[- 1 , 0.5 ], None ],
376+ [[0.5 , - 1 ], None ],
377+ ]
378+ )
379+ def test_cursor_data_nonuniform (xy , data ):
380+ from matplotlib .backend_bases import MouseEvent
381+
382+ # Non-linear set of x-values
383+ x = np .array ([0 , 1 , 4 , 9 , 16 ])
384+ y = np .array ([0 , 1 , 2 , 3 , 4 ])
385+ z = x [np .newaxis , :]** 2 + y [:, np .newaxis ]** 2
386+
387+ fig , ax = plt .subplots ()
388+ im = NonUniformImage (ax , extent = (x .min (), x .max (), y .min (), y .max ()))
389+ im .set_data (x , y , z )
390+ ax .add_image (im )
391+ # Set lower min lim so we can test cursor outside image
392+ ax .set_xlim (x .min () - 2 , x .max ())
393+ ax .set_ylim (y .min () - 2 , y .max ())
394+
395+ xdisp , ydisp = ax .transData .transform (xy )
396+ event = MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
397+ assert im .get_cursor_data (event ) == data , (im .get_cursor_data (event ), data )
398+
399+
368400@pytest .mark .parametrize (
369401 "data, text" , [
370402 ([[10001 , 10000 ]], "[10001.000]" ),
0 commit comments