Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 580cda5

Browse files
authored
[TST] Add test_annotate in test_datetime.py (#27222)
* smoke test for axes.annotate in datetime * fixed tests using numeric data instead of dates * smoke test for axes.annotate in test.datetime
1 parent b19a5b8 commit 580cda5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@ def test_acorr(self):
1414
fig, ax = plt.subplots()
1515
ax.acorr(...)
1616

17-
@pytest.mark.xfail(reason="Test for annotate not written yet")
1817
@mpl.style.context("default")
1918
def test_annotate(self):
20-
fig, ax = plt.subplots()
21-
ax.annotate(...)
19+
mpl.rcParams["date.converter"] = 'concise'
20+
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, layout="constrained")
21+
22+
start_date = datetime.datetime(2023, 10, 1)
23+
dates = [start_date + datetime.timedelta(days=i) for i in range(31)]
24+
data = list(range(1, 32))
25+
test_text = "Test Text"
26+
27+
ax1.plot(dates, data)
28+
ax1.annotate(text=test_text, xy=(dates[15], data[15]))
29+
ax2.plot(data, dates)
30+
ax2.annotate(text=test_text, xy=(data[5], dates[26]))
31+
ax3.plot(dates, dates)
32+
ax3.annotate(text=test_text, xy=(dates[15], dates[3]))
33+
ax4.plot(dates, dates)
34+
ax4.annotate(text=test_text, xy=(dates[5], dates[30]),
35+
xytext=(dates[1], dates[7]), arrowprops=dict(facecolor='red'))
2236

2337
@pytest.mark.xfail(reason="Test for arrow not written yet")
2438
@mpl.style.context("default")

0 commit comments

Comments
 (0)