Skip to content

Commit a79b87c

Browse files
Add test for sharex stacked subplots axis separation
1 parent d645f6a commit a79b87c

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎plotly/matplotlylib/tests/test_renderer.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@ def test_right_axis_ticks_hidden_when_mpl_right_ticks_hidden():
266266
assert plotly_fig.layout.yaxis2.ticks == ""
267267

268268

269+
def test_sharex_stacked_lines_in_correct_subplots():
270+
"""Test that vertically stacked subplots with sharex=True place lines in separate subplots."""
271+
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
272+
ax1.plot([1, 2, 3], [4, 5, 6])
273+
ax2.plot([1, 2, 3], [10, 20, 30])
274+
275+
plotly_fig = tls.mpl_to_plotly(fig)
276+
277+
assert len(plotly_fig.data) == 2
278+
# First line belongs to the top subplot
279+
assert plotly_fig.data[0].yaxis in (None, "y", "y1")
280+
# Second line belongs to the bottom subplot
281+
assert plotly_fig.data[1].yaxis == "y2"
282+
283+
# Distinct non-overlapping vertical domains (top above bottom)
284+
assert plotly_fig.layout.yaxis.domain[0] > plotly_fig.layout.yaxis2.domain[1]
285+
286+
# The bottom subplot must not overlay the top subplot
287+
assert plotly_fig.layout.yaxis2.overlaying is None
288+
assert plotly_fig.layout.xaxis2.overlaying is None
289+
290+
269291
def test_violinplot_bodies_are_filled_polygons():
270292
fig, ax = plt.subplots()
271293
ax.violinplot(np.random.randn(100, 3))

0 commit comments

Comments
 (0)