@@ -1395,7 +1395,7 @@ def test_mixed_style_lines_group_consecutive_matches():
13951395
13961396
13971397def test_axhspan_converts ():
1398- """axhspan converts to a layout shape spanning the axes width ."""
1398+ """axhspan converts to a layout shape spanning the x axis domain ."""
13991399 fig , ax = plt .subplots ()
14001400 ax .axhspan (0.25 , 0.75 )
14011401
@@ -1405,19 +1405,18 @@ def test_axhspan_converts():
14051405 assert len (plotly_fig .layout .shapes ) == 1
14061406 shape = plotly_fig .layout .shapes [0 ]
14071407 assert shape .type == "rect"
1408- x0 , x1 = ax .get_xlim ()
1409- assert abs (shape .x0 - x0 ) < 1e-9
1410- assert abs (shape .x1 - x1 ) < 1e-9
1408+ assert abs (shape .x0 - 0 ) < 1e-9
1409+ assert abs (shape .x1 - 1 ) < 1e-9
14111410 assert abs (shape .y0 - 0.25 ) < 1e-9
14121411 assert abs (shape .y1 - 0.75 ) < 1e-9
1413- assert shape .xref == "x"
1412+ assert shape .xref == "x domain "
14141413 assert shape .yref == "y"
14151414 assert shape .fillcolor == "#1F77B4"
14161415 assert shape .layer == "below"
14171416
14181417
14191418def test_axvspan_converts ():
1420- """axvspan converts to a layout shape spanning the axes height ."""
1419+ """axvspan converts to a layout shape spanning the y axis domain ."""
14211420 fig , ax = plt .subplots ()
14221421 ax .axvspan (0.25 , 0.75 )
14231422
@@ -1427,17 +1426,47 @@ def test_axvspan_converts():
14271426 assert len (plotly_fig .layout .shapes ) == 1
14281427 shape = plotly_fig .layout .shapes [0 ]
14291428 assert shape .type == "rect"
1430- y0 , y1 = ax .get_ylim ()
14311429 assert abs (shape .x0 - 0.25 ) < 1e-9
14321430 assert abs (shape .x1 - 0.75 ) < 1e-9
1433- assert abs (shape .y0 - y0 ) < 1e-9
1434- assert abs (shape .y1 - y1 ) < 1e-9
1431+ assert abs (shape .y0 - 0 ) < 1e-9
1432+ assert abs (shape .y1 - 1 ) < 1e-9
14351433 assert shape .xref == "x"
1436- assert shape .yref == "y"
1434+ assert shape .yref == "y domain "
14371435 assert shape .fillcolor == "#1F77B4"
14381436 assert shape .layer == "below"
14391437
14401438
1439+ def test_axhspan_axes_fractions_convert ():
1440+ """axhspan xmin/xmax convert to x axis domain fractions and axvspan
1441+ ymin/ymax convert to y axis domain fractions."""
1442+ fig , ax = plt .subplots ()
1443+ ax .plot ([0 , 10 ], [0 , 10 ])
1444+ ax .axhspan (2 , 4 , xmin = 0.2 , xmax = 0.6 )
1445+ ax .axvspan (6 , 8 , ymin = 0.1 , ymax = 0.5 )
1446+
1447+ plotly_fig = tls .mpl_to_plotly (fig )
1448+
1449+ hspan , vspan = plotly_fig .layout .shapes
1450+ assert hspan .xref == "x domain"
1451+ assert hspan .yref == "y"
1452+ assert np .allclose ([hspan .x0 , hspan .x1 , hspan .y0 , hspan .y1 ], [0.2 , 0.6 , 2 , 4 ])
1453+ assert vspan .xref == "x"
1454+ assert vspan .yref == "y domain"
1455+ assert np .allclose ([vspan .x0 , vspan .x1 , vspan .y0 , vspan .y1 ], [6 , 8 , 0.1 , 0.5 ])
1456+
1457+
1458+ def test_axhspan_on_second_subplot_references_its_domain ():
1459+ """Spans on a second subplot reference that subplot's axis domain."""
1460+ fig , (ax1 , ax2 ) = plt .subplots (1 , 2 )
1461+ ax2 .axhspan (2 , 4 )
1462+
1463+ plotly_fig = tls .mpl_to_plotly (fig )
1464+
1465+ (shape ,) = plotly_fig .layout .shapes
1466+ assert shape .xref == "x2 domain"
1467+ assert shape .yref == "y2"
1468+
1469+
14411470def test_axhspan_with_custom_style_converts ():
14421471 """axhspan with custom colors and alpha converts to a styled layout shape."""
14431472 fig , ax = plt .subplots ()
0 commit comments