1414import matplotlib as mpl
1515from matplotlib import (
1616 colors , image as mimage , patches , pyplot as plt , style , rcParams )
17+ from matplotlib .backend_bases import MouseEvent
1718from matplotlib .image import (AxesImage , BboxImage , FigureImage ,
1819 NonUniformImage , PcolorImage )
1920from matplotlib .patches import Rectangle
@@ -455,8 +456,6 @@ def test_cursor_data_nonuniform(xy, data):
455456 ([[0 , 0 ]], "[0.00]" ),
456457 ])
457458def test_format_cursor_data (data , text ):
458- from matplotlib .backend_bases import MouseEvent
459-
460459 fig , ax = plt .subplots ()
461460 im = ax .imshow (data )
462461
@@ -465,14 +464,23 @@ def test_format_cursor_data(data, text):
465464 assert im .format_cursor_data (im .get_cursor_data (event )) == text
466465
467466
467+ def test_format_cursor_data_uint8_no_norm ():
468+ data = np .array ([[0 , 44 ]], dtype = np .uint8 )
469+ fig , ax = plt .subplots ()
470+ im = ax .imshow (data , norm = colors .NoNorm ())
471+
472+ xdisp , ydisp = ax .transData .transform ([1 , 0 ])
473+ event = MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
474+ assert im .format_cursor_data (im .get_cursor_data (event )) == "[44.000]"
475+
476+
468477@pytest .mark .parametrize (
469478 "data, text" , [
470479 ([[[10001 , 10000 ]], [[0 , 0 ]]], "[10001.000, 0.000]" ),
471480 ([[[.123 , .987 ]], [[0.1 , 0 ]]], "[0.123, 0.100]" ),
472481 ([[[np .nan , 1 , 2 ]], [[0 , 0 , 0 ]]], "[]" ),
473482 ])
474483def test_format_cursor_data_multinorm (data , text ):
475- from matplotlib .backend_bases import MouseEvent
476484 fig , ax = plt .subplots ()
477485 cmap_bivar = mpl .bivar_colormaps ['BiOrangeBlue' ]
478486 cmap_multivar = mpl .multivar_colormaps ['2VarAddA' ]
0 commit comments