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

Skip to content

Commit f3585ef

Browse files
linyililyLinyi Li
and
Linyi Li
authored
Add test for fill_between in test_datetime.py (matplotlib#27423)
* add test for fill_between in test_datetime.py * fix error in checks * make y values always increasing * second plot removed as requested * oops forgot to remove savefig --------- Co-authored-by: Linyi Li <[email protected]>
1 parent de1be12 commit f3585ef

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,40 @@ def test_fill(self):
311311
ax3.fill(x_values, y_values)
312312
ax4.fill(x_dates, y_dates)
313313

314-
@pytest.mark.xfail(reason="Test for fill_between not written yet")
315314
@mpl.style.context("default")
316315
def test_fill_between(self):
317-
fig, ax = plt.subplots()
318-
ax.fill_between(...)
316+
mpl.rcParams["date.converter"] = "concise"
317+
np.random.seed(19680801)
318+
319+
y_base_date = datetime.datetime(2023, 1, 1)
320+
y_dates1 = [y_base_date]
321+
for i in range(1, 10):
322+
y_base_date += datetime.timedelta(days=np.random.randint(1, 5))
323+
y_dates1.append(y_base_date)
324+
325+
y_dates2 = [y_base_date]
326+
for i in range(1, 10):
327+
y_base_date += datetime.timedelta(days=np.random.randint(1, 5))
328+
y_dates2.append(y_base_date)
329+
x_values = np.random.rand(10) * 10
330+
x_values.sort()
331+
332+
y_values1 = np.random.rand(10) * 10
333+
y_values2 = y_values1 + np.random.rand(10) * 10
334+
y_values1.sort()
335+
y_values2.sort()
336+
337+
x_base_date = datetime.datetime(2023, 1, 1)
338+
x_dates = [x_base_date]
339+
for i in range(1, 10):
340+
x_base_date += datetime.timedelta(days=np.random.randint(1, 10))
341+
x_dates.append(x_base_date)
342+
343+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained")
344+
345+
ax1.fill_between(x_values, y_dates1, y_dates2)
346+
ax2.fill_between(x_dates, y_values1, y_values2)
347+
ax3.fill_between(x_dates, y_dates1, y_dates2)
319348

320349
@pytest.mark.xfail(reason="Test for fill_betweenx not written yet")
321350
@mpl.style.context("default")

0 commit comments

Comments
 (0)