From 2761fa6d5292c496aa32581465ccbfe1b459775b Mon Sep 17 00:00:00 2001 From: Koustav Ghosh Date: Fri, 6 Oct 2023 13:52:16 +0530 Subject: [PATCH 1/3] Add test_contour #26864 --- lib/matplotlib/tests/test_datetime.py | 33 ++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 53958229f174..503885883eda 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -116,11 +116,38 @@ def test_cohere(self): fig, ax = plt.subplots() ax.cohere(...) - @pytest.mark.xfail(reason="Test for contour not written yet") @mpl.style.context("default") def test_contour(self): - fig, ax = plt.subplots() - ax.contour(...) + mpl.rcParams["date.converter"] = "concise" + range_threshold = 10 + fig, (ax1, ax2, ax3, bx1, bx2, bx3) = plt.subplots( + 6, 1, layout="constrained", figsize=(6, 10) + ) + + x_dates = np.array( + [datetime.datetime(2023, 10, delta) for delta in range(1, range_threshold)] + ) + y_dates = np.array( + [datetime.datetime(2023, 10, delta) for delta in range(1, range_threshold)] + ) + x_timestamps = np.array([datetime.datetime.timestamp(data) for data in x_dates]) + y_timestamps = np.array([datetime.datetime.timestamp(data) for data in y_dates]) + x_ranges = np.array(range(1, range_threshold)) + y_ranges = np.array(range(1, range_threshold)) + + X_dates, Y_dates = np.meshgrid(x_dates, y_dates) + X_ranges, Y_ranges = np.meshgrid(x_ranges, y_ranges) + X_timestamps, Y_timestamps = np.meshgrid(x_timestamps, y_timestamps) + + # function to transform x, y values in order to create contour graph + f = lambda x, y: np.cos(x / 4) + np.sin(y / 4) + + ax1.contour(X_dates, Y_dates, f(X_timestamps, Y_timestamps)) + ax2.contour(X_dates, Y_ranges, f(X_timestamps, Y_timestamps)) + ax3.contour(X_ranges, Y_dates, f(X_timestamps, Y_timestamps)) + bx1.contour(X_dates, Y_dates, f(X_ranges, Y_ranges)) + bx2.contour(X_dates, Y_ranges, f(X_ranges, Y_ranges)) + bx3.contour(X_ranges, Y_dates, f(X_ranges, Y_ranges)) @pytest.mark.xfail(reason="Test for contourf not written yet") @mpl.style.context("default") From c7a171079bff279ff93d174b2302c6fa0d39519a Mon Sep 17 00:00:00 2001 From: Koustav Ghosh Date: Fri, 6 Oct 2023 13:52:16 +0530 Subject: [PATCH 2/3] Add test_contour #26864 Modify test_contour #26864 --- lib/matplotlib/tests/test_datetime.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 503885883eda..3313fbdd5115 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -139,15 +139,15 @@ def test_contour(self): X_ranges, Y_ranges = np.meshgrid(x_ranges, y_ranges) X_timestamps, Y_timestamps = np.meshgrid(x_timestamps, y_timestamps) - # function to transform x, y values in order to create contour graph - f = lambda x, y: np.cos(x / 4) + np.sin(y / 4) - - ax1.contour(X_dates, Y_dates, f(X_timestamps, Y_timestamps)) - ax2.contour(X_dates, Y_ranges, f(X_timestamps, Y_timestamps)) - ax3.contour(X_ranges, Y_dates, f(X_timestamps, Y_timestamps)) - bx1.contour(X_dates, Y_dates, f(X_ranges, Y_ranges)) - bx2.contour(X_dates, Y_ranges, f(X_ranges, Y_ranges)) - bx3.contour(X_ranges, Y_dates, f(X_ranges, Y_ranges)) + Z_timestamps = np.cos(X_timestamps / 4) + np.sin(Y_timestamps / 4) + Z_ranges = np.cos(X_ranges / 4) + np.sin(Y_ranges / 4) + + ax1.contour(X_dates, Y_dates, Z_timestamps) + ax2.contour(X_dates, Y_ranges, Z_timestamps) + ax3.contour(X_ranges, Y_dates, Z_timestamps) + bx1.contour(X_dates, Y_dates, Z_ranges) + bx2.contour(X_dates, Y_ranges, Z_ranges) + bx3.contour(X_ranges, Y_dates, Z_ranges) @pytest.mark.xfail(reason="Test for contourf not written yet") @mpl.style.context("default") From 6bc09d7d6fa8bb9dbe509188f8b3b23a68a82246 Mon Sep 17 00:00:00 2001 From: Koustav Ghosh Date: Tue, 12 Dec 2023 11:44:41 +0530 Subject: [PATCH 3/3] Removed test_cohere and repetitive tests --- lib/matplotlib/tests/test_datetime.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index dfe7c895a6df..6c490d9b6467 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -104,19 +104,11 @@ def test_clabel(self): fig, ax = plt.subplots() ax.clabel(...) - @pytest.mark.xfail(reason="Test for cohere not written yet") - @mpl.style.context("default") - def test_cohere(self): - fig, ax = plt.subplots() - ax.cohere(...) - @mpl.style.context("default") def test_contour(self): mpl.rcParams["date.converter"] = "concise" range_threshold = 10 - fig, (ax1, ax2, ax3, bx1, bx2, bx3) = plt.subplots( - 6, 1, layout="constrained", figsize=(6, 10) - ) + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained") x_dates = np.array( [datetime.datetime(2023, 10, delta) for delta in range(1, range_threshold)] @@ -124,24 +116,17 @@ def test_contour(self): y_dates = np.array( [datetime.datetime(2023, 10, delta) for delta in range(1, range_threshold)] ) - x_timestamps = np.array([datetime.datetime.timestamp(data) for data in x_dates]) - y_timestamps = np.array([datetime.datetime.timestamp(data) for data in y_dates]) x_ranges = np.array(range(1, range_threshold)) y_ranges = np.array(range(1, range_threshold)) X_dates, Y_dates = np.meshgrid(x_dates, y_dates) X_ranges, Y_ranges = np.meshgrid(x_ranges, y_ranges) - X_timestamps, Y_timestamps = np.meshgrid(x_timestamps, y_timestamps) - Z_timestamps = np.cos(X_timestamps / 4) + np.sin(Y_timestamps / 4) Z_ranges = np.cos(X_ranges / 4) + np.sin(Y_ranges / 4) - ax1.contour(X_dates, Y_dates, Z_timestamps) - ax2.contour(X_dates, Y_ranges, Z_timestamps) - ax3.contour(X_ranges, Y_dates, Z_timestamps) - bx1.contour(X_dates, Y_dates, Z_ranges) - bx2.contour(X_dates, Y_ranges, Z_ranges) - bx3.contour(X_ranges, Y_dates, Z_ranges) + ax1.contour(X_dates, Y_dates, Z_ranges) + ax2.contour(X_dates, Y_ranges, Z_ranges) + ax3.contour(X_ranges, Y_dates, Z_ranges) @pytest.mark.xfail(reason="Test for contourf not written yet") @mpl.style.context("default")