diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index cec2fa891e80..b8015b32fdd4 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt import matplotlib as mpl +import matplotlib.dates as dt class TestDatetimePlotting: @@ -545,11 +546,28 @@ def test_pcolor(self): fig, ax = plt.subplots() ax.pcolor(...) - @pytest.mark.xfail(reason="Test for pcolorfast not written yet") @mpl.style.context("default") def test_pcolorfast(self): + np.random.seed(19680801) + + ''' + Directly inputting either datetime.datetime or numpy.datetime64 + without using date2num() seems to always generate compile errors for pcolorfast(). + I have used date2num() to ensure that the graph prints correctly + despite that such operations may defy the purpose of conducting such tests. + ''' + basedate_x = datetime.datetime(2023, 12, 6, 1, 30, 30) + basedate_y = datetime.datetime(2024, 5, 5, 12, 15, 45) + dates_x = [dt.date2num(basedate_x + datetime.timedelta(days=1*i, hours=6*i, minutes=20*i)) for i in range(10)] + dates_y = [dt.date2num(basedate_y + datetime.timedelta(days=1*i, hours=8*i, minutes=30*i)) for i in range(10)] + data = np.random.rand(0, 100) + fig, ax = plt.subplots() - ax.pcolorfast(...) + pc = ax.pcolorfast(dates_x, dates_y, data) + + ax.set_xlabel('Sample datetime') + ax.set_ylabel('Sample data') + ax.set_title('Sample test case for pcolorfast()') @pytest.mark.xfail(reason="Test for pcolormesh not written yet") @mpl.style.context("default")