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

Skip to content

Commit cac8c78

Browse files
Add test_boxplot to test_datetime.py
1 parent 4524fdb commit cac8c78

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,32 @@ def test_barh(self):
171171
ax2.set_ylabel('Order of Birth Dates')
172172
ax2.barh(np.arange(4), birth_date-year_start, left=year_start)
173173

174-
@pytest.mark.xfail(reason="Test for boxplot not written yet")
175174
@mpl.style.context("default")
176175
def test_boxplot(self):
177-
fig, ax = plt.subplots()
178-
ax.boxplot(...)
176+
mpl.rcParams["date.converter"] = "concise"
177+
178+
fig, (ax1, ax2) = plt.subplots(2, 1, layout="constrained")
179+
180+
dates1 = [
181+
datetime(2023, 1, 1),
182+
datetime(2023, 1, 10),
183+
datetime(2023, 1, 15),
184+
datetime(2023, 1, 20)
185+
]
186+
187+
time_diffs = [(date - min(dates1)).total_seconds() for date in dates1]
188+
189+
ax1.boxplot(time_diffs)
190+
191+
np.random.seed(19680801)
192+
193+
dates2 = [datetime(2023, 1, 1) +
194+
datetime.timedelta(days=np.random.randint(1, 365))
195+
for _ in range(100)]
196+
197+
timestamps = [(date - datetime(1970, 1, 1)).total_seconds() for date in dates2]
198+
199+
ax2.boxplot(timestamps)
179200

180201
@pytest.mark.xfail(reason="Test for broken_barh not written yet")
181202
@mpl.style.context("default")

0 commit comments

Comments
 (0)