From 2d70e18573048d993293385b953920bcea2199e2 Mon Sep 17 00:00:00 2001 From: danielcobej Date: Wed, 18 Oct 2023 02:07:29 +0200 Subject: [PATCH 1/3] added test_axvspan --- lib/matplotlib/tests/test_datetime.py | 29 ++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 72701cd2d8cd..87e9e51afef1 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -50,11 +50,34 @@ 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) + time_delta = datetime.timedelta(days=1) + + values1 = np.random.randint(1, 10, 30) + values2 = np.random.randint(1, 10, 30) + values3 = np.random.randint(1, 10, 30) + + bin_edges = [start_date + i * time_delta for i in range(31)] + + fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True) + + axes = [ax1, ax2, ax3] + values_list = [values1, values2, values3] + + for ax, values in zip(axes, values_list): + ax.hist( + [start_date + i * time_delta for i in range(30)], + bins=bin_edges, + weights=values + ) + for i in range(np.random.randint(1, 5)): + xmin = start_date + np.random.randint(0, 30) * time_delta + xmax = xmin + np.random.randint(1, 3) * time_delta + ax.axvspan(xmin=xmin, xmax=xmax, facecolor='green', alpha=0.5) @pytest.mark.xfail(reason="Test for bar not written yet") @mpl.style.context("default") From eb0ff88cde0b1b497d17ffb836d19f13f923aeae Mon Sep 17 00:00:00 2001 From: danielcobej Date: Wed, 18 Oct 2023 03:37:36 +0200 Subject: [PATCH 2/3] added random seed number --- lib/matplotlib/tests/test_datetime.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 87e9e51afef1..fb6eedc3b5e0 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -53,6 +53,7 @@ def test_axvline(self): @mpl.style.context("default") def test_axvspan(self): mpl.rcParams["date.converter"] = 'concise' + np.random.seed(19680801) start_date = datetime.datetime(2023, 1, 1) time_delta = datetime.timedelta(days=1) From 46e0dc258b019fc90cd5c0eb9e9584cbe3fd7837 Mon Sep 17 00:00:00 2001 From: danielcobej Date: Sun, 22 Oct 2023 17:53:05 +0200 Subject: [PATCH 3/3] datetime vs datetime, number vs datetime, datetime vs number --- lib/matplotlib/tests/test_datetime.py | 55 +++++++++++++++------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index fb6eedc3b5e0..993948d8f106 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -53,32 +53,39 @@ def test_axvline(self): @mpl.style.context("default") def test_axvspan(self): mpl.rcParams["date.converter"] = 'concise' - np.random.seed(19680801) start_date = datetime.datetime(2023, 1, 1) - time_delta = datetime.timedelta(days=1) - - values1 = np.random.randint(1, 10, 30) - values2 = np.random.randint(1, 10, 30) - values3 = np.random.randint(1, 10, 30) - - bin_edges = [start_date + i * time_delta for i in range(31)] - - fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True) - - axes = [ax1, ax2, ax3] - values_list = [values1, values2, values3] - - for ax, values in zip(axes, values_list): - ax.hist( - [start_date + i * time_delta for i in range(30)], - bins=bin_edges, - weights=values - ) - for i in range(np.random.randint(1, 5)): - xmin = start_date + np.random.randint(0, 30) * time_delta - xmax = xmin + np.random.randint(1, 3) * time_delta - ax.axvspan(xmin=xmin, xmax=xmax, facecolor='green', alpha=0.5) + 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") 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