From 4e45a67c6a139a23a5c7e20faf595ec5331e4a20 Mon Sep 17 00:00:00 2001 From: Shriya Kalakata Date: Thu, 7 Dec 2023 17:49:30 -0500 Subject: [PATCH 1/4] Add test_eventplot to test_datetime.py --- lib/matplotlib/tests/test_datetime.py | 31 ++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index b19124a1b764..54fd43bbb286 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -260,11 +260,36 @@ def test_errorbar(self): uplims=True, xuplims=True, label='Data') - @pytest.mark.xfail(reason="Test for eventplot not written yet") @mpl.style.context("default") def test_eventplot(self): - fig, ax = plt.subplots() - ax.eventplot(...) + mpl.rcParams["date.converter"] = "concise" + + fig, (ax1, ax2) = plt.subplots(2, 1, layout="constrained") + + x_dates1 = np.array([ + datetime.datetime(2020, 6, 30), + datetime.datetime(2020, 7, 22), + datetime.datetime(2020, 8, 3), + datetime.datetime(2020, 9, 14), + ], dtype=np.datetime64) + + ax1.eventplot(x_dates1) + + x_dates2 = np.array([ + [datetime.datetime(2020, 6, 30), datetime.datetime(2020, 7, 22), + datetime.datetime(2020, 8, 3), datetime.datetime(2020, 9, 14)], + [datetime.datetime(2020, 7, 18), datetime.datetime(2020, 7, 21), + datetime.datetime(2020, 8, 3), datetime.datetime(2020, 10, 14)] + ], dtype=np.datetime64) + + colors = ['C{}'.format(i) for i in range(2)] + lineoffsets = np.array([1, 6]) + linelengths = [5, 2] + + ax2.eventplot(x_dates2, + colors=colors, + lineoffsets=lineoffsets, + linelengths=linelengths) @pytest.mark.xfail(reason="Test for fill not written yet") @mpl.style.context("default") From a676dce422688d5d9b52b0f6b5aceabb8a5a5fd3 Mon Sep 17 00:00:00 2001 From: Shriya Kalakata Date: Thu, 7 Dec 2023 23:19:45 -0500 Subject: [PATCH 2/4] Modified test to check for input with varying lengths of data --- lib/matplotlib/tests/test_datetime.py | 43 ++++++++++++++------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 54fd43bbb286..11974d5782c4 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -266,30 +266,31 @@ def test_eventplot(self): fig, (ax1, ax2) = plt.subplots(2, 1, layout="constrained") - x_dates1 = np.array([ - datetime.datetime(2020, 6, 30), - datetime.datetime(2020, 7, 22), - datetime.datetime(2020, 8, 3), - datetime.datetime(2020, 9, 14), - ], dtype=np.datetime64) + x_dates1 = np.array([datetime.datetime(2020, 6, 30), + datetime.datetime(2020, 7, 22), + datetime.datetime(2020, 8, 3), + datetime.datetime(2020, 9, 14),], + dtype=np.datetime64, + ) ax1.eventplot(x_dates1) - x_dates2 = np.array([ - [datetime.datetime(2020, 6, 30), datetime.datetime(2020, 7, 22), - datetime.datetime(2020, 8, 3), datetime.datetime(2020, 9, 14)], - [datetime.datetime(2020, 7, 18), datetime.datetime(2020, 7, 21), - datetime.datetime(2020, 8, 3), datetime.datetime(2020, 10, 14)] - ], dtype=np.datetime64) - - colors = ['C{}'.format(i) for i in range(2)] - lineoffsets = np.array([1, 6]) - linelengths = [5, 2] - - ax2.eventplot(x_dates2, - colors=colors, - lineoffsets=lineoffsets, - linelengths=linelengths) + start_date = datetime.datetime(2020, 7, 1) + end_date = datetime.datetime(2020, 10, 15) + date_range = end_date - start_date + + dates1 = start_date + np.random.rand(30) * date_range + dates2 = start_date + np.random.rand(10) * date_range + dates3 = start_date + np.random.rand(50) * date_range + + colors1 = ['C1', 'C2', 'C3'] + lineoffsets1 = np.array([1, 6, 8]) + linelengths1 = [5, 2, 3] + + ax2.eventplot([dates1, dates2, dates3], + colors=colors1, + lineoffsets=lineoffsets1, + linelengths=linelengths1) @pytest.mark.xfail(reason="Test for fill not written yet") @mpl.style.context("default") From bf397911866e825ea80248e896bacdec3bfb07c4 Mon Sep 17 00:00:00 2001 From: Shriya Kalakata Date: Fri, 8 Dec 2023 00:47:51 -0500 Subject: [PATCH 3/4] Set random seed --- lib/matplotlib/tests/test_datetime.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 11974d5782c4..cf5bd82d2223 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -275,6 +275,8 @@ def test_eventplot(self): ax1.eventplot(x_dates1) + np.random.seed(19680801) + start_date = datetime.datetime(2020, 7, 1) end_date = datetime.datetime(2020, 10, 15) date_range = end_date - start_date From f55957e2d6d46eaefb520f16cc1bfa616a087e5e Mon Sep 17 00:00:00 2001 From: Shriya Kalakata Date: Fri, 8 Dec 2023 18:04:33 -0500 Subject: [PATCH 4/4] Added third test for Axes.eventplot --- lib/matplotlib/tests/test_datetime.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index cf5bd82d2223..0b6ac467a062 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -264,7 +264,7 @@ def test_errorbar(self): def test_eventplot(self): mpl.rcParams["date.converter"] = "concise" - fig, (ax1, ax2) = plt.subplots(2, 1, layout="constrained") + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained") x_dates1 = np.array([datetime.datetime(2020, 6, 30), datetime.datetime(2020, 7, 22), @@ -294,6 +294,17 @@ def test_eventplot(self): lineoffsets=lineoffsets1, linelengths=linelengths1) + lineoffsets2 = np.array([ + datetime.datetime(2020, 7, 1), + datetime.datetime(2020, 7, 15), + datetime.datetime(2020, 8, 1) + ], dtype=np.datetime64) + + ax3.eventplot([dates1, dates2, dates3], + colors=colors1, + lineoffsets=lineoffsets2, + linelengths=linelengths1) + @pytest.mark.xfail(reason="Test for fill not written yet") @mpl.style.context("default") def test_fill(self):