Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c6fb79

Browse files
Added Axes.stairs test in test_datetime.py (#27424)
* Completed Axes.stairs test_datetime.py Tested error-free * Update test_datetime.py * Reverting unexpected changes in test_datetime.py in the previous commit * Update test_stairs as requested * Fixing linting errors * Adding Baseline data for the test * Fixing linting error * Update stairs test as suggested Co-authored-by: Elliott Sales de Andrade <[email protected]> * Update stairs test as suggested Co-authored-by: Elliott Sales de Andrade <[email protected]> --------- Co-authored-by: Elliott Sales de Andrade <[email protected]>
1 parent b2e3e8b commit 1c6fb79

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,27 @@ def test_stackplot(self):
711711
fig, ax = plt.subplots(layout='constrained')
712712
ax.stackplot(dates, stacked_nums)
713713

714-
@pytest.mark.xfail(reason="Test for stairs not written yet")
715714
@mpl.style.context("default")
716715
def test_stairs(self):
717-
fig, ax = plt.subplots()
718-
ax.stairs(...)
716+
mpl.rcParams["date.converter"] = 'concise'
717+
718+
start_date = datetime.datetime(2023, 12, 1)
719+
time_delta = datetime.timedelta(days=1)
720+
baseline_date = datetime.datetime(1980, 1, 1)
721+
722+
bin_edges = [start_date + i * time_delta for i in range(31)]
723+
edge_int = np.arange(31)
724+
np.random.seed(123456)
725+
values1 = np.random.randint(1, 100, 30)
726+
values2 = [start_date + datetime.timedelta(days=int(i))
727+
for i in np.random.randint(1, 10000, 30)]
728+
values3 = [start_date + datetime.timedelta(days=int(i))
729+
for i in np.random.randint(-10000, 10000, 30)]
730+
731+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True)
732+
ax1.stairs(values1, edges=bin_edges)
733+
ax2.stairs(values2, edges=edge_int, baseline=baseline_date)
734+
ax3.stairs(values3, edges=bin_edges, baseline=baseline_date)
719735

720736
@mpl.style.context("default")
721737
def test_stem(self):

0 commit comments

Comments
 (0)