From 3d353e962f04a65201c75de4bd40b2b3233378c6 Mon Sep 17 00:00:00 2001 From: rawwash Date: Wed, 29 Nov 2023 10:08:51 -0500 Subject: [PATCH 1/4] added test case for pcolor --- lib/matplotlib/tests/test_datetime.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 316be793e47c..4f07f284dd8c 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -399,11 +399,15 @@ def test_matshow(self): fig, ax = plt.subplots() ax.matshow(...) - @pytest.mark.xfail(reason="Test for pcolor not written yet") @mpl.style.context("default") def test_pcolor(self): + data = np.random.rand(10, 10) fig, ax = plt.subplots() - ax.pcolor(...) + c = ax.pcolor(data) + fig.colorbar(c, ax=ax) + ax.set_title('Pseudocolor Plot Test') + assert c is not None, "Failed to create pcolor plot" + plt.close(fig) @pytest.mark.xfail(reason="Test for pcolorfast not written yet") @mpl.style.context("default") From fd4c2c50cbe0281b84572ed75cd46ecddd1ac664 Mon Sep 17 00:00:00 2001 From: rawwash Date: Wed, 29 Nov 2023 16:51:56 -0500 Subject: [PATCH 2/4] adding datetime to pcolor --- lib/matplotlib/tests/test_datetime.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 4f07f284dd8c..7ff3049ca3f0 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -401,12 +401,32 @@ def test_matshow(self): @mpl.style.context("default") def test_pcolor(self): + # Generate a range of dates + base_date = datetime.date(2020, 1, 1) + dates = [base_date + datetime.timedelta(days=i) for i in range(10)] + + # Convert dates to Matplotlib date numbers + mpl_dates = mpl.dates.date2num(dates) + + # Create a 2D array with date numbers in one axis data = np.random.rand(10, 10) + data[0, :] = mpl_dates # Assuming dates are in the first row for example + + # Create the pcolor plot fig, ax = plt.subplots() c = ax.pcolor(data) fig.colorbar(c, ax=ax) - ax.set_title('Pseudocolor Plot Test') - assert c is not None, "Failed to create pcolor plot" + + # Format the axis to interpret the first row as dates + ax.set_yticks(np.arange(0.5, len(dates), 1)) + ax.set_yticklabels([d.strftime('%Y-%m-%d') for d in dates]) + + ax.set_title('Pseudocolor Plot with Datetime Data') + + # Assert that the pcolor plot is created + assert c is not None, "Failed to create pcolor plot with datetime data" + plt.show() + # Close the plot to free up resources plt.close(fig) @pytest.mark.xfail(reason="Test for pcolorfast not written yet") From 7316aaaa61f8c1ad6100000c94384d7ee59c3de2 Mon Sep 17 00:00:00 2001 From: rawwash Date: Wed, 29 Nov 2023 22:30:30 -0500 Subject: [PATCH 3/4] pcolor with correct datetime functionality --- lib/matplotlib/tests/test_datetime.py | 31 +++++++++------------------ 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 7ff3049ca3f0..ae2b161bc430 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -401,32 +401,17 @@ def test_matshow(self): @mpl.style.context("default") def test_pcolor(self): - # Generate a range of dates base_date = datetime.date(2020, 1, 1) dates = [base_date + datetime.timedelta(days=i) for i in range(10)] - - # Convert dates to Matplotlib date numbers - mpl_dates = mpl.dates.date2num(dates) - - # Create a 2D array with date numbers in one axis data = np.random.rand(10, 10) - data[0, :] = mpl_dates # Assuming dates are in the first row for example - - # Create the pcolor plot + data = np.sort(data, axis=0) fig, ax = plt.subplots() - c = ax.pcolor(data) - fig.colorbar(c, ax=ax) - - # Format the axis to interpret the first row as dates - ax.set_yticks(np.arange(0.5, len(dates), 1)) - ax.set_yticklabels([d.strftime('%Y-%m-%d') for d in dates]) - + c = ax.pcolor(data, cmap='viridis') ax.set_title('Pseudocolor Plot with Datetime Data') - - # Assert that the pcolor plot is created - assert c is not None, "Failed to create pcolor plot with datetime data" - plt.show() - # Close the plot to free up resources + ax.set_xticks(range(len(dates))) + ax.set_xticklabels([d.strftime('%Y-%m-%d') for d in dates], rotation=45) + fig.colorbar(c, ax=ax) + fig.tight_layout() plt.close(fig) @pytest.mark.xfail(reason="Test for pcolorfast not written yet") @@ -635,3 +620,7 @@ def test_vlines(self): def test_xcorr(self): fig, ax = plt.subplots() ax.xcorr(...) + +if __name__ == "__main__": + test = TestDatetimePlotting() + test.test_pcolor() From 9a0ac90fb080b18aedc70cfbfa81f6deade6ac93 Mon Sep 17 00:00:00 2001 From: rawwash Date: Wed, 29 Nov 2023 22:33:06 -0500 Subject: [PATCH 4/4] removing if main --- lib/matplotlib/tests/test_datetime.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index ae2b161bc430..f7fd3e2a6623 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -620,7 +620,3 @@ def test_vlines(self): def test_xcorr(self): fig, ax = plt.subplots() ax.xcorr(...) - -if __name__ == "__main__": - test = TestDatetimePlotting() - test.test_pcolor() 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