Skip to content

Commit 4af8697

Browse files
committed
datetime vs number, number vs datetime, datetime vs datetime
1 parent 42c4ef0 commit 4af8697

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,39 @@ def test_axhline(self):
3535
@mpl.style.context("default")
3636
def test_axhspan(self):
3737
mpl.rcParams["date.converter"] = 'concise'
38-
np.random.seed(19680801)
3938

4039
start_date = datetime.datetime(2023, 1, 1)
41-
time_delta = datetime.timedelta(days=1)
42-
43-
fig, (ax1, ax2) = plt.subplots(2, 1, constrained_layout=True, figsize=(10, 8))
44-
45-
ax1.set_ylim(start_date, start_date + 29*time_delta)
46-
for i in range(np.random.randint(1, 5)):
47-
ymin = start_date + np.random.randint(0, 30) * time_delta
48-
ymax = ymin + np.random.randint(1, 3) * time_delta
49-
ax1.axhspan(ymin=ymin, ymax=ymax, facecolor='green', alpha=0.5)
50-
51-
ax2.set_ylim(start_date, start_date + 29*time_delta)
52-
for i in range(0, 30, 2):
53-
ymin = start_date + i * time_delta
54-
ymax = ymin + time_delta
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)
5558
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')
5671

5772
@pytest.mark.xfail(reason="Test for axline not written yet")
5873
@mpl.style.context("default")

0 commit comments

Comments
 (0)