Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b34e704

Browse filesBrowse files
Merge pull request #27130 from danielcobej/add_axvspan
added test_axvspan in test.datetime.py
2 parents e501543 + 46e0dc2 commit b34e704
Copy full SHA for b34e704

File tree

Expand file treeCollapse file tree

1 file changed

+34
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-3
lines changed

‎lib/matplotlib/tests/test_datetime.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_datetime.py
+34-3Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.