Skip to content

Commit 2d70e18

Browse files
committed
added test_axvspan
1 parent 1d6f09f commit 2d70e18

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,34 @@ def test_axvline(self):
5050
fig, ax = plt.subplots()
5151
ax.axvline(...)
5252

53-
@pytest.mark.xfail(reason="Test for axvspan not written yet")
5453
@mpl.style.context("default")
5554
def test_axvspan(self):
56-
fig, ax = plt.subplots()
57-
ax.axvspan(...)
55+
mpl.rcParams["date.converter"] = 'concise'
56+
57+
start_date = datetime.datetime(2023, 1, 1)
58+
time_delta = datetime.timedelta(days=1)
59+
60+
values1 = np.random.randint(1, 10, 30)
61+
values2 = np.random.randint(1, 10, 30)
62+
values3 = np.random.randint(1, 10, 30)
63+
64+
bin_edges = [start_date + i * time_delta for i in range(31)]
65+
66+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True)
67+
68+
axes = [ax1, ax2, ax3]
69+
values_list = [values1, values2, values3]
70+
71+
for ax, values in zip(axes, values_list):
72+
ax.hist(
73+
[start_date + i * time_delta for i in range(30)],
74+
bins=bin_edges,
75+
weights=values
76+
)
77+
for i in range(np.random.randint(1, 5)):
78+
xmin = start_date + np.random.randint(0, 30) * time_delta
79+
xmax = xmin + np.random.randint(1, 3) * time_delta
80+
ax.axvspan(xmin=xmin, xmax=xmax, facecolor='green', alpha=0.5)
5881

5982
@pytest.mark.xfail(reason="Test for bar not written yet")
6083
@mpl.style.context("default")

0 commit comments

Comments
 (0)