Skip to content

Commit 7dc9cfd

Browse files
committed
Add test to validate xtick alignment for scatter and line plots
This test ensures that the x-axis ticks are consistent between scatter and line plots when sharing the same axis. It addresses a potential issue related to GH#61005, verifying proper rendering of datetime x-axis labels.
1 parent 241c96c commit 7dc9cfd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/plotting/test_series.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,17 @@ def test_secondary_y_subplot_axis_labels(self):
971971
s1.plot(ax=ax2)
972972
assert len(ax.xaxis.get_minor_ticks()) == 0
973973
assert len(ax.get_xticklabels()) > 0
974+
975+
def test_scatter_line_xticks(self):
976+
# GH#61005
977+
datetime_list = [datetime(year=2025, month=1, day=1, hour=n) for n in range(3)]
978+
df = DataFrame(columns=["datetime", "y"])
979+
for i, n in enumerate(datetime_list):
980+
df.loc[len(df)] = [n, i]
981+
fig, ax = plt.subplots(2, sharex=True)
982+
df.plot.scatter(x="datetime", y="y", ax=ax[0])
983+
scatter_xticks = ax[0].get_xticks()
984+
df.plot(x="datetime", y="y", ax=ax[1])
985+
line_xticks = ax[1].get_xticks()
986+
assert scatter_xticks[0] == line_xticks[0]
987+
assert scatter_xticks[-1] == line_xticks[-1]

0 commit comments

Comments
 (0)