From a4abcce443edbe4abda1c3e7b3b74094565d16aa Mon Sep 17 00:00:00 2001 From: Linyi Li Date: Sat, 2 Dec 2023 14:54:28 -0500 Subject: [PATCH 1/5] add test for fill_between in test_datetime.py --- lib/matplotlib/tests/test_datetime.py | 34 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index ca8e1cb90732..7417fbb57743 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -311,11 +311,39 @@ def test_fill(self): ax3.fill(x_values, y_values) ax4.fill(x_dates, y_dates) - @pytest.mark.xfail(reason="Test for fill_between not written yet") @mpl.style.context("default") def test_fill_between(self): - fig, ax = plt.subplots() - ax.fill_between(...) + mpl.rcParams["date.converter"] = "concise" + np.random.seed(19680801) + + y_base_date = datetime.datetime(2023, 1, 1) + y_dates1 = [y_base_date] + for i in range(1, 10): + y_base_date += datetime.timedelta(days=np.random.randint(1, 5)) + y_dates1.append(y_base_date) + + y_dates2 = [y_base_date] + for i in range(1, 10): + y_base_date += datetime.timedelta(days=np.random.randint(1, 5)) + y_dates2.append(y_base_date) + x_values = np.random.rand(10) * 10 + x_values.sort() + + y_values1 = np.random.rand(10) *10 + y_values2 = y_values1 + np.random.rand(10) *10 + + x_base_date = datetime.datetime(2023, 1, 1) + x_dates = [x_base_date] + for _ in range(1, 10): + x_base_date += datetime.timedelta(days=np.random.randint(1, 10)) + x_dates.append(x_base_date) + + fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, layout="constrained") + + ax1.fill_between(x_values, y_dates1, y_dates2) + ax2.fill_between(x_values, y_values1, y_values2) + ax3.fill_between(x_dates, y_values1, y_values2) + ax4.fill_between(x_dates, y_dates1, y_dates2) @pytest.mark.xfail(reason="Test for fill_betweenx not written yet") @mpl.style.context("default") From aa4a096cf273265914ce95cda85180d7b2ff39bc Mon Sep 17 00:00:00 2001 From: Linyi Li Date: Sat, 2 Dec 2023 15:09:52 -0500 Subject: [PATCH 2/5] fix error in checks --- lib/matplotlib/tests/test_datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 7417fbb57743..ea11c984073b 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -329,8 +329,8 @@ def test_fill_between(self): x_values = np.random.rand(10) * 10 x_values.sort() - y_values1 = np.random.rand(10) *10 - y_values2 = y_values1 + np.random.rand(10) *10 + y_values1 = np.random.rand(10) * 10 + y_values2 = y_values1 + np.random.rand(10) * 10 x_base_date = datetime.datetime(2023, 1, 1) x_dates = [x_base_date] From 608776b916019d21d351c9b10738448880c1f735 Mon Sep 17 00:00:00 2001 From: Linyi Li Date: Sat, 2 Dec 2023 15:36:00 -0500 Subject: [PATCH 3/5] make y values always increasing --- 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 ea11c984073b..0a3f108d77d7 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -331,10 +331,12 @@ def test_fill_between(self): y_values1 = np.random.rand(10) * 10 y_values2 = y_values1 + np.random.rand(10) * 10 + y_values1.sort() + y_values2.sort() x_base_date = datetime.datetime(2023, 1, 1) x_dates = [x_base_date] - for _ in range(1, 10): + for i in range(1, 10): x_base_date += datetime.timedelta(days=np.random.randint(1, 10)) x_dates.append(x_base_date) From 5b66de3d96515164c9069cfc59b71d4a9498e461 Mon Sep 17 00:00:00 2001 From: Linyi Li Date: Mon, 4 Dec 2023 22:01:21 -0500 Subject: [PATCH 4/5] second plot removed as requested --- lib/matplotlib/tests/test_datetime.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 0a3f108d77d7..8e7c03fa92c7 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -340,12 +340,13 @@ def test_fill_between(self): x_base_date += datetime.timedelta(days=np.random.randint(1, 10)) x_dates.append(x_base_date) - fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, layout="constrained") + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained") ax1.fill_between(x_values, y_dates1, y_dates2) - ax2.fill_between(x_values, y_values1, y_values2) - ax3.fill_between(x_dates, y_values1, y_values2) - ax4.fill_between(x_dates, y_dates1, y_dates2) + ax2.fill_between(x_dates, y_values1, y_values2) + ax3.fill_between(x_dates, y_dates1, y_dates2) + + plt.savefig("fill_between2.png") @pytest.mark.xfail(reason="Test for fill_betweenx not written yet") @mpl.style.context("default") From 32193969babe3ffc37e85ab0acae2662ee86fce6 Mon Sep 17 00:00:00 2001 From: Linyi Li Date: Mon, 4 Dec 2023 22:02:17 -0500 Subject: [PATCH 5/5] oops forgot to remove savefig --- lib/matplotlib/tests/test_datetime.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 8e7c03fa92c7..ca9c09e45fe7 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -346,8 +346,6 @@ def test_fill_between(self): ax2.fill_between(x_dates, y_values1, y_values2) ax3.fill_between(x_dates, y_dates1, y_dates2) - plt.savefig("fill_between2.png") - @pytest.mark.xfail(reason="Test for fill_betweenx not written yet") @mpl.style.context("default") def test_fill_betweenx(self): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy