@@ -81,11 +81,42 @@ def test_axvline(self):
8181 fig , ax = plt .subplots ()
8282 ax .axvline (...)
8383
84- @pytest .mark .xfail (reason = "Test for axvspan not written yet" )
8584 @mpl .style .context ("default" )
8685 def test_axvspan (self ):
87- fig , ax = plt .subplots ()
88- ax .axvspan (...)
86+ mpl .rcParams ["date.converter" ] = 'concise'
87+
88+ start_date = datetime .datetime (2023 , 1 , 1 )
89+ dates = [start_date + datetime .timedelta (days = i ) for i in range (31 )]
90+ numbers = list (range (1 , 32 ))
91+
92+ fig , (ax1 , ax2 , ax3 ) = plt .subplots (3 , 1 ,
93+ constrained_layout = True ,
94+ figsize = (10 , 12 ))
95+
96+ ax1 .plot (dates , numbers , marker = 'o' , color = 'blue' )
97+ for i in range (0 , 31 , 2 ):
98+ xmin = start_date + datetime .timedelta (days = i )
99+ xmax = xmin + datetime .timedelta (days = 1 )
100+ ax1 .axvspan (xmin = xmin , xmax = xmax , facecolor = 'red' , alpha = 0.5 )
101+ ax1 .set_title ('Datetime vs. Number' )
102+ ax1 .set_xlabel ('Date' )
103+ ax1 .set_ylabel ('Number' )
104+
105+ ax2 .plot (numbers , dates , marker = 'o' , color = 'blue' )
106+ for i in range (0 , 31 , 2 ):
107+ ax2 .axvspan (xmin = i + 1 , xmax = i + 2 , facecolor = 'red' , alpha = 0.5 )
108+ ax2 .set_title ('Number vs. Datetime' )
109+ ax2 .set_xlabel ('Number' )
110+ ax2 .set_ylabel ('Date' )
111+
112+ ax3 .plot (dates , dates , marker = 'o' , color = 'blue' )
113+ for i in range (0 , 31 , 2 ):
114+ xmin = start_date + datetime .timedelta (days = i )
115+ xmax = xmin + datetime .timedelta (days = 1 )
116+ ax3 .axvspan (xmin = xmin , xmax = xmax , facecolor = 'red' , alpha = 0.5 )
117+ ax3 .set_title ('Datetime vs. Datetime' )
118+ ax3 .set_xlabel ('Date' )
119+ ax3 .set_ylabel ('Date' )
89120
90121 @pytest .mark .xfail (reason = "Test for bar not written yet" )
91122 @mpl .style .context ("default" )
0 commit comments