@@ -32,11 +32,42 @@ 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+
39+ start_date = datetime .datetime (2023 , 1 , 1 )
40+ dates = [start_date + datetime .timedelta (days = i ) for i in range (31 )]
41+ numbers = list (range (1 , 32 ))
42+
43+ fig , (ax1 , ax2 , ax3 ) = plt .subplots (3 , 1 ,
44+ constrained_layout = True ,
45+ figsize = (10 , 12 ))
46+
47+ ax1 .plot (dates , numbers , marker = 'o' , color = 'blue' )
48+ for i in range (0 , 31 , 2 ):
49+ ax1 .axhspan (ymin = i + 1 , ymax = i + 2 , facecolor = 'green' , alpha = 0.5 )
50+ ax1 .set_title ('Datetime vs. Number' )
51+ ax1 .set_xlabel ('Date' )
52+ ax1 .set_ylabel ('Number' )
53+
54+ ax2 .plot (numbers , dates , marker = 'o' , color = 'blue' )
55+ for i in range (0 , 31 , 2 ):
56+ ymin = start_date + datetime .timedelta (days = i )
57+ ymax = ymin + datetime .timedelta (days = 1 )
58+ ax2 .axhspan (ymin = ymin , ymax = ymax , facecolor = 'green' , alpha = 0.5 )
59+ ax2 .set_title ('Number vs. Datetime' )
60+ ax2 .set_xlabel ('Number' )
61+ ax2 .set_ylabel ('Date' )
62+
63+ ax3 .plot (dates , dates , marker = 'o' , color = 'blue' )
64+ for i in range (0 , 31 , 2 ):
65+ ymin = start_date + datetime .timedelta (days = i )
66+ ymax = ymin + datetime .timedelta (days = 1 )
67+ ax3 .axhspan (ymin = ymin , ymax = ymax , facecolor = 'green' , alpha = 0.5 )
68+ ax3 .set_title ('Datetime vs. Datetime' )
69+ ax3 .set_xlabel ('Date' )
70+ ax3 .set_ylabel ('Date' )
4071
4172 @pytest .mark .xfail (reason = "Test for axline not written yet" )
4273 @mpl .style .context ("default" )
0 commit comments