Skip to content

Raise an error when a make_subplots span overlaps another subplot - #5858

Draft
LukeTheoJohnson wants to merge 2 commits into
plotly:mainfrom
LukeTheoJohnson:fix-subplots-spanned-cell-overlap
Draft

LukeTheoJohnson wants to merge 2 commits into
plotly:mainfrom
LukeTheoJohnson:fix-subplots-spanned-cell-overlap

Conversation

@LukeTheoJohnson

Copy link
Copy Markdown
Contributor

Link to issue

Closes #5335

Description of change

make_subplots now raises a ValueError when a cell covered by a colspan or rowspan also holds a subplot in specs. Before, the two subplots were drawn on top of each other. The specs docstring already says to use None to move past a span.

Demo

from plotly.subplots import make_subplots

fig = make_subplots(rows=1, cols=3, specs=[[{"colspan": 2}, {}, None]])

On main the second subplot lands in column 2, inside the spanning one:

fig.layout.xaxis.domain   # (0.0, 0.6444444444444445)
fig.layout.xaxis2.domain  # (0.35555555555555557, 0.6444444444444445)

With this change:

ValueError: The subplot at grid position (1, 1) spans the cell at (1, 2), so specs[0][1] must be None.

The layout from the issue is specs=[[{"colspan": 2}, None, {}]], which already works and isn't changed.

Testing strategy

Two tests in test_make_subplots.py, one for an overlapping colspan and one for an overlapping rowspan. Both fail on main (nothing is raised) and pass with this change. tests/test_core plus test_px, test_figure_factory and test_subplots under tests/test_optional give the same results as main. ruff check and ruff format --check are clean.

Additional information (optional)

Specs that overlap like this today will now raise instead of drawing. The covered cell's subplot always sits inside the span's cells, and insets covers the case where an overlap is wanted.

Guidelines

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

subplots: colspan >1 to the left of a normal subplot puts the right subplot in the wrong place

1 participant