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

Skip to content

Commit 5814cf3

Browse files
authored
Merge pull request #27142 from 0taj/test_text
Added smoke test for Axes.text in test_datetime.py
2 parents f7e74da + 3783494 commit 5814cf3

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,33 @@ def test_streamplot(self):
393393
fig, ax = plt.subplots()
394394
ax.streamplot(...)
395395

396-
@pytest.mark.xfail(reason="Test for text not written yet")
397396
@mpl.style.context("default")
398397
def test_text(self):
399-
fig, ax = plt.subplots()
400-
ax.text(...)
398+
mpl.rcParams["date.converter"] = 'concise'
399+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained")
400+
401+
limit_value = 10
402+
font_properties = {'family': 'serif', 'size': 12, 'weight': 'bold'}
403+
test_date = datetime.datetime(2023, 10, 1)
404+
405+
x_data = np.array(range(1, limit_value))
406+
y_data = np.array(range(1, limit_value))
407+
408+
x_dates = np.array(
409+
[datetime.datetime(2023, 10, n) for n in range(1, limit_value)]
410+
)
411+
y_dates = np.array(
412+
[datetime.datetime(2023, 10, n) for n in range(1, limit_value)]
413+
)
414+
415+
ax1.plot(x_dates, y_data)
416+
ax1.text(test_date, 5, "Inserted Text", **font_properties)
417+
418+
ax2.plot(x_data, y_dates)
419+
ax2.text(7, test_date, "Inserted Text", **font_properties)
420+
421+
ax3.plot(x_dates, y_dates)
422+
ax3.text(test_date, test_date, "Inserted Text", **font_properties)
401423

402424
@pytest.mark.xfail(reason="Test for tricontour not written yet")
403425
@mpl.style.context("default")

0 commit comments

Comments
 (0)