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

Skip to content

Commit 87e09e8

Browse files
authored
Merge pull request #27466 from shriyakalakata/eventplot
Add test_eventplot to test_datetime.py
2 parents d48b2a8 + f55957e commit 87e09e8

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,50 @@ def test_errorbar(self):
330330
uplims=True, xuplims=True,
331331
label='Data')
332332

333-
@pytest.mark.xfail(reason="Test for eventplot not written yet")
334333
@mpl.style.context("default")
335334
def test_eventplot(self):
336-
fig, ax = plt.subplots()
337-
ax.eventplot(...)
335+
mpl.rcParams["date.converter"] = "concise"
336+
337+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained")
338+
339+
x_dates1 = np.array([datetime.datetime(2020, 6, 30),
340+
datetime.datetime(2020, 7, 22),
341+
datetime.datetime(2020, 8, 3),
342+
datetime.datetime(2020, 9, 14),],
343+
dtype=np.datetime64,
344+
)
345+
346+
ax1.eventplot(x_dates1)
347+
348+
np.random.seed(19680801)
349+
350+
start_date = datetime.datetime(2020, 7, 1)
351+
end_date = datetime.datetime(2020, 10, 15)
352+
date_range = end_date - start_date
353+
354+
dates1 = start_date + np.random.rand(30) * date_range
355+
dates2 = start_date + np.random.rand(10) * date_range
356+
dates3 = start_date + np.random.rand(50) * date_range
357+
358+
colors1 = ['C1', 'C2', 'C3']
359+
lineoffsets1 = np.array([1, 6, 8])
360+
linelengths1 = [5, 2, 3]
361+
362+
ax2.eventplot([dates1, dates2, dates3],
363+
colors=colors1,
364+
lineoffsets=lineoffsets1,
365+
linelengths=linelengths1)
366+
367+
lineoffsets2 = np.array([
368+
datetime.datetime(2020, 7, 1),
369+
datetime.datetime(2020, 7, 15),
370+
datetime.datetime(2020, 8, 1)
371+
], dtype=np.datetime64)
372+
373+
ax3.eventplot([dates1, dates2, dates3],
374+
colors=colors1,
375+
lineoffsets=lineoffsets2,
376+
linelengths=linelengths1)
338377

339378
@mpl.style.context("default")
340379
def test_fill(self):

0 commit comments

Comments
 (0)