From c563085b554080ae57f61972271b91f9c71fa457 Mon Sep 17 00:00:00 2001 From: CozyFrog Date: Fri, 13 Oct 2023 15:27:19 -0400 Subject: [PATCH 1/3] Add test_barh in test_datetime.py --- lib/matplotlib/tests/test_datetime.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 53958229f174..46bcf5071295 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -80,11 +80,18 @@ def test_barbs(self): fig, ax = plt.subplots() ax.barbs(...) - @pytest.mark.xfail(reason="Test for barh not written yet") @mpl.style.context("default") def test_barh(self): - fig, ax = plt.subplots() - ax.barh(...) + mpl.rcParams["date.converter"] = 'concise' + N = 14 + base = datetime.datetime(1970, 1, 1) + indices = np.arange(N) + dates = [base + datetime.timedelta(days=(7 * i)) for i in range(N)] + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout='constrained') + error = np.random.rand(N) + ax1.barh(indices, dates, xerr=error) + ax2.barh(dates, indices) + ax3.barh(dates, dates) @pytest.mark.xfail(reason="Test for boxplot not written yet") @mpl.style.context("default") From 18358eb2a99c8844c07414e8536277242647e86d Mon Sep 17 00:00:00 2001 From: CozyFrog Date: Fri, 13 Oct 2023 16:41:52 -0400 Subject: [PATCH 2/3] Add test for parameters width and left --- lib/matplotlib/tests/test_datetime.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index c5e55b3c3958..b035a7873083 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -81,11 +81,13 @@ def test_barh(self): base = datetime.datetime(1970, 1, 1) indices = np.arange(N) dates = [base + datetime.timedelta(days=(7 * i)) for i in range(N)] - fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout='constrained') + widths = [datetime.timedelta(days=(7*i)) for i in range(N)] + fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, layout='constrained') error = np.random.rand(N) ax1.barh(indices, dates, xerr=error) ax2.barh(dates, indices) ax3.barh(dates, dates) + ax4.barh(indices, width=widths, left=base) @pytest.mark.xfail(reason="Test for boxplot not written yet") @mpl.style.context("default") From fb0802d333af9d20571c4368d775afc4484a191b Mon Sep 17 00:00:00 2001 From: CozyFrog Date: Tue, 17 Oct 2023 15:45:13 -0400 Subject: [PATCH 3/3] Make suggested modifications to test_barh in test_datetime.py --- lib/matplotlib/tests/test_datetime.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index b035a7873083..900eb3643a21 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -77,17 +77,21 @@ def test_barbs(self): @mpl.style.context("default") def test_barh(self): mpl.rcParams["date.converter"] = 'concise' - N = 14 - base = datetime.datetime(1970, 1, 1) - indices = np.arange(N) - dates = [base + datetime.timedelta(days=(7 * i)) for i in range(N)] - widths = [datetime.timedelta(days=(7*i)) for i in range(N)] - fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, layout='constrained') - error = np.random.rand(N) - ax1.barh(indices, dates, xerr=error) - ax2.barh(dates, indices) - ax3.barh(dates, dates) - ax4.barh(indices, width=widths, left=base) + fig, (ax1, ax2) = plt.subplots(2, 1, layout='constrained') + birth_date = np.array([datetime.datetime(2020, 4, 10), + datetime.datetime(2020, 5, 30), + datetime.datetime(2020, 10, 12), + datetime.datetime(2020, 11, 15)]) + year_start = datetime.datetime(2020, 1, 1) + year_end = datetime.datetime(2020, 12, 31) + age = [21, 53, 20, 24] + ax1.set_xlabel('Age') + ax1.set_ylabel('Birth Date') + ax1.barh(birth_date, width=age, height=datetime.timedelta(days=10)) + ax2.set_xlim(left=year_start, right=year_end) + ax2.set_xlabel('Birth Date') + ax2.set_ylabel('Order of Birth Dates') + ax2.barh(np.arange(4), birth_date-year_start, left=year_start) @pytest.mark.xfail(reason="Test for boxplot not written yet") @mpl.style.context("default")