diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 72701cd2d8cd..993948d8f106 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -50,11 +50,42 @@ def test_axvline(self): fig, ax = plt.subplots() ax.axvline(...) - @pytest.mark.xfail(reason="Test for axvspan not written yet") @mpl.style.context("default") def test_axvspan(self): - fig, ax = plt.subplots() - ax.axvspan(...) + 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): + xmin = start_date + datetime.timedelta(days=i) + xmax = xmin + datetime.timedelta(days=1) + ax1.axvspan(xmin=xmin, xmax=xmax, facecolor='red', 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): + ax2.axvspan(xmin=i+1, xmax=i+2, facecolor='red', 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): + xmin = start_date + datetime.timedelta(days=i) + xmax = xmin + datetime.timedelta(days=1) + ax3.axvspan(xmin=xmin, xmax=xmax, facecolor='red', alpha=0.5) + ax3.set_title('Datetime vs. Datetime') + ax3.set_xlabel('Date') + ax3.set_ylabel('Date') @pytest.mark.xfail(reason="Test for bar not written yet") @mpl.style.context("default")
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: