Skip to content

Commit 8ed678d

Browse files
committed
Fix bar and line plot alignment and x-axis visibility in tests
Ensure bar and line plots share consistent x-axis tick labels and verify that x-axis limits are adjusted to make all plotted elements visible in `test_bar_line_plot` test. These changes improve the robustness of visual alignment and boundary checks.
1 parent 168b271 commit 8ed678d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pandas/tests/plotting/test_series.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,13 +975,22 @@ def test_secondary_y_subplot_axis_labels(self):
975975
def test_bar_line_plot(self):
976976
"""
977977
Test that bar and line plots with the same x values are superposed
978+
and that the x limits are set such that the plots are visible.
978979
"""
979980
# GH61161
980981
index = period_range("2023", periods=3, freq="Y")
982+
years = set(index.year.astype(str))
981983
s = Series([1, 2, 3], index=index)
982984
ax = plt.subplot()
983985
s.plot(kind="bar", ax=ax)
984-
bar_xticks = ax.get_xticks().tolist()
986+
bar_xticks = [
987+
label for label in ax.get_xticklabels() if label.get_text() in years
988+
]
985989
s.plot(kind="line", ax=ax, color="r")
986-
line_xticks = ax.get_xticks()[: len(s)].tolist()
987-
assert line_xticks == bar_xticks
990+
line_xticks = [
991+
label for label in ax.get_xticklabels() if label.get_text() in years
992+
]
993+
assert bar_xticks == line_xticks
994+
x_limits = ax.get_xlim()
995+
assert x_limits[0] <= bar_xticks[0].get_position()[0]
996+
assert x_limits[1] >= bar_xticks[-1].get_position()[0]

0 commit comments

Comments
 (0)