Skip to content

Keep overall trendline off marginal subplots - #5780

Open
jayzhou2309 wants to merge 2 commits into
plotly:mainfrom
jayzhou2309:fix/overall-trendline-marginals
Open

jayzhou2309 wants to merge 2 commits into
plotly:mainfrom
jayzhou2309:fix/overall-trendline-marginals

Conversation

@jayzhou2309

Copy link
Copy Markdown

Link to issue

Closes #4669

Description of change

With trendline_scope="overall", make_figure added the overall trendline with row="all", col="all", exclude_empty_subplots=True. The marginal_x row and marginal_y column already hold the box/histogram/violin traces, so they are not empty, and the trendline was drawn on them too. This PR adds the trendline only to the main cells: every row except the top one when marginal_x is set, and every column except the right one when marginal_y is set. Facets keep one trendline per facet as before.

Demo

px.scatter(px.data.tips(), x="total_bill", y="tip", color="sex", marginal_x="box", marginal_y="box", trendline="ols", trendline_scope="overall"), axes of the Overall Trendline traces:

  • main (d586d22): (x, y), (x2, y2), (x3, y3)
  • this PR: (x, y)

Testing strategy

  • test_overall_trendline_skips_marginals checks that the overall trendlines sit on exactly the subplots that hold the scatter points, for marginal_x + marginal_y, marginal_x + facet_col, and marginal_y + facet_row, across the pandas, pyarrow and polars backends. It fails on main (9 failed) and passes here (9 passed).
  • tests/test_optional/test_px and tests/test_core: 1697 passed, 11 skipped, 4 xfailed.
  • Checked by hand that facet_col_wrap=2 with marginal_x gives one trendline per facet, none on the marginal row, and one legend entry.
  • ruff check and ruff format --check pass on the changed files.

AI disclosure

An AI agent (Claude Code) reproduced the issue, wrote the failing test and the fix, and ran the commands above.

Guidelines


🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.

jayzhou2309 and others added 2 commits September 29, 2026 02:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
make_figure added the overall trendline with row="all", col="all", so
it landed on every non-empty subplot, including the marginal_x row and
marginal_y column. Add it only to the main (facet) cells.

Closes plotly#4669

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

marginal-distribution subplots include overall-trendline

1 participant