diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 276b7c179afe..ca8b746bad0d 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -32,11 +32,42 @@ def test_axhline(self): fig, ax = plt.subplots() ax.axhline(...) - @pytest.mark.xfail(reason="Test for axhspan not written yet") @mpl.style.context("default") def test_axhspan(self): - fig, ax = plt.subplots() - ax.axhspan(...) + mpl.rcParams["date.converter"] = 'concise' + + start_date = datetime.datetime(2023, 1, 1) + dates = [start_date + datetime.timedelta(days=i) for i in range(31)] + numbers = list(range(1, 32)) + + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, + constrained_layout=True, + figsize=(10, 12)) + + ax1.plot(dates, numbers, marker='o', color='blue') + for i in range(0, 31, 2): + ax1.axhspan(ymin=i+1, ymax=i+2, facecolor='green', alpha=0.5) + ax1.set_title('Datetime vs. Number') + ax1.set_xlabel('Date') + ax1.set_ylabel('Number') + + ax2.plot(numbers, dates, marker='o', color='blue') + for i in range(0, 31, 2): + ymin = start_date + datetime.timedelta(days=i) + ymax = ymin + datetime.timedelta(days=1) + ax2.axhspan(ymin=ymin, ymax=ymax, facecolor='green', alpha=0.5) + ax2.set_title('Number vs. Datetime') + ax2.set_xlabel('Number') + ax2.set_ylabel('Date') + + ax3.plot(dates, dates, marker='o', color='blue') + for i in range(0, 31, 2): + ymin = start_date + datetime.timedelta(days=i) + ymax = ymin + datetime.timedelta(days=1) + ax3.axhspan(ymin=ymin, ymax=ymax, facecolor='green', alpha=0.5) + ax3.set_title('Datetime vs. Datetime') + ax3.set_xlabel('Date') + ax3.set_ylabel('Date') @pytest.mark.xfail(reason="Test for axline not written yet") @mpl.style.context("default") 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