@@ -32,11 +32,37 @@ def test_axhline(self):
3232 fig , ax = plt .subplots ()
3333 ax .axhline (...)
3434
35- @pytest .mark .xfail (reason = "Test for axhspan not written yet" )
3635 @mpl .style .context ("default" )
3736 def test_axhspan (self ):
38- fig , ax = plt .subplots ()
39- ax .axhspan (...)
37+ mpl .rcParams ["date.converter" ] = 'concise'
38+ np .random .seed (19680801 )
39+
40+ start_date = datetime .datetime (2023 , 1 , 1 )
41+ time_delta = datetime .timedelta (days = 1 )
42+
43+ values = np .random .randint (1 , 10 , 30 )
44+ bin_edges = [start_date + i * time_delta for i in range (31 )]
45+
46+ fig , (ax1 , ax2 ) = plt .subplots (2 , 1 , constrained_layout = True )
47+
48+ ax1 .hist (
49+ [start_date + i * time_delta for i in range (30 )],
50+ bins = bin_edges ,
51+ weights = values )
52+
53+ for i in range (np .random .randint (1 , 5 )):
54+ ymin = np .random .randint (1 , 8 )
55+ ymax = ymin + np .random .randint (1 , 3 )
56+ ax1 .axhspan (ymin = ymin , ymax = ymax , facecolor = 'green' , alpha = 0.5 )
57+
58+ ax2 .hist (
59+ [start_date + i * time_delta for i in range (30 )],
60+ bins = bin_edges ,
61+ weights = values )
62+
63+ y_values = np .unique (values )
64+ for i , y in enumerate (y_values [::2 ]):
65+ ax2 .axhspan (ymin = y , ymax = y + 1 , facecolor = 'green' , alpha = 0.5 )
4066
4167 @pytest .mark .xfail (reason = "Test for axline not written yet" )
4268 @mpl .style .context ("default" )
0 commit comments