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

Skip to content

Commit a589856

Browse files
Add scatter test for datetime units (#26882)
* test_axes added 3 subplots with datetime array on the x axis, y axis, and both axes. * incorporated issues in previous PR * deleted whitespaces after end of line * got rid of space in 311 * Simplified datetime array * fixed mistake in previous commit * Update test_datetime.py I needed to rotate axis labels because they were still clogged after I reduced array length * Update test_datetime.py eliminated unused variable according to feedback ('lims')
1 parent 1d1171f commit a589856

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
@@ -301,11 +301,27 @@ def test_quiverkey(self):
301301
fig, ax = plt.subplots()
302302
ax.quiverkey(...)
303303

304-
@pytest.mark.xfail(reason="Test for scatter not written yet")
305304
@mpl.style.context("default")
306305
def test_scatter(self):
307-
fig, ax = plt.subplots()
308-
ax.scatter(...)
306+
mpl.rcParams["date.converter"] = 'concise'
307+
base = datetime.datetime(2005, 2, 1)
308+
dates = [base + datetime.timedelta(hours=(2 * i)) for i in range(10)]
309+
N = len(dates)
310+
np.random.seed(19680801)
311+
y = np.cumsum(np.random.randn(N))
312+
fig, axs = plt.subplots(3, 1, layout='constrained', figsize=(6, 6))
313+
# datetime array on x axis
314+
axs[0].scatter(dates, y)
315+
for label in axs[0].get_xticklabels():
316+
label.set_rotation(40)
317+
label.set_horizontalalignment('right')
318+
# datetime on y axis
319+
axs[1].scatter(y, dates)
320+
# datetime on both x, y axes
321+
axs[2].scatter(dates, dates)
322+
for label in axs[2].get_xticklabels():
323+
label.set_rotation(40)
324+
label.set_horizontalalignment('right')
309325

310326
@pytest.mark.xfail(reason="Test for semilogx not written yet")
311327
@mpl.style.context("default")

0 commit comments

Comments
 (0)