@@ -53,32 +53,39 @@ def test_axvline(self):
53
53
@mpl .style .context ("default" )
54
54
def test_axvspan (self ):
55
55
mpl .rcParams ["date.converter" ] = 'concise'
56
- np .random .seed (19680801 )
57
56
58
57
start_date = datetime .datetime (2023 , 1 , 1 )
59
- time_delta = datetime .timedelta (days = 1 )
60
-
61
- values1 = np .random .randint (1 , 10 , 30 )
62
- values2 = np .random .randint (1 , 10 , 30 )
63
- values3 = np .random .randint (1 , 10 , 30 )
64
-
65
- bin_edges = [start_date + i * time_delta for i in range (31 )]
66
-
67
- fig , (ax1 , ax2 , ax3 ) = plt .subplots (3 , 1 , constrained_layout = True )
68
-
69
- axes = [ax1 , ax2 , ax3 ]
70
- values_list = [values1 , values2 , values3 ]
71
-
72
- for ax , values in zip (axes , values_list ):
73
- ax .hist (
74
- [start_date + i * time_delta for i in range (30 )],
75
- bins = bin_edges ,
76
- weights = values
77
- )
78
- for i in range (np .random .randint (1 , 5 )):
79
- xmin = start_date + np .random .randint (0 , 30 ) * time_delta
80
- xmax = xmin + np .random .randint (1 , 3 ) * time_delta
81
- ax .axvspan (xmin = xmin , xmax = xmax , facecolor = 'green' , alpha = 0.5 )
58
+ dates = [start_date + datetime .timedelta (days = i ) for i in range (31 )]
59
+ numbers = list (range (1 , 32 ))
60
+
61
+ fig , (ax1 , ax2 , ax3 ) = plt .subplots (3 , 1 ,
62
+ constrained_layout = True ,
63
+ figsize = (10 , 12 ))
64
+
65
+ ax1 .plot (dates , numbers , marker = 'o' , color = 'blue' )
66
+ for i in range (0 , 31 , 2 ):
67
+ xmin = start_date + datetime .timedelta (days = i )
68
+ xmax = xmin + datetime .timedelta (days = 1 )
69
+ ax1 .axvspan (xmin = xmin , xmax = xmax , facecolor = 'red' , alpha = 0.5 )
70
+ ax1 .set_title ('Datetime vs. Number' )
71
+ ax1 .set_xlabel ('Date' )
72
+ ax1 .set_ylabel ('Number' )
73
+
74
+ ax2 .plot (numbers , dates , marker = 'o' , color = 'blue' )
75
+ for i in range (0 , 31 , 2 ):
76
+ ax2 .axvspan (xmin = i + 1 , xmax = i + 2 , facecolor = 'red' , alpha = 0.5 )
77
+ ax2 .set_title ('Number vs. Datetime' )
78
+ ax2 .set_xlabel ('Number' )
79
+ ax2 .set_ylabel ('Date' )
80
+
81
+ ax3 .plot (dates , dates , marker = 'o' , color = 'blue' )
82
+ for i in range (0 , 31 , 2 ):
83
+ xmin = start_date + datetime .timedelta (days = i )
84
+ xmax = xmin + datetime .timedelta (days = 1 )
85
+ ax3 .axvspan (xmin = xmin , xmax = xmax , facecolor = 'red' , alpha = 0.5 )
86
+ ax3 .set_title ('Datetime vs. Datetime' )
87
+ ax3 .set_xlabel ('Date' )
88
+ ax3 .set_ylabel ('Date' )
82
89
83
90
@pytest .mark .xfail (reason = "Test for bar not written yet" )
84
91
@mpl .style .context ("default" )
0 commit comments