Keep overall trendline off marginal subplots - #5780
Open
jayzhou2309 wants to merge 2 commits into
Open
jayzhou2309 wants to merge 2 commits into
jayzhou2309 wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #4669
Description of change
With
trendline_scope="overall",make_figureadded the overall trendline withrow="all", col="all", exclude_empty_subplots=True. Themarginal_xrow andmarginal_ycolumn 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 whenmarginal_xis set, and every column except the right one whenmarginal_yis 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 theOverall Trendlinetraces:(x, y),(x2, y2),(x3, y3)(x, y)Testing strategy
test_overall_trendline_skips_marginalschecks that the overall trendlines sit on exactly the subplots that hold the scatter points, formarginal_x+marginal_y,marginal_x+facet_col, andmarginal_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_pxandtests/test_core: 1697 passed, 11 skipped, 4 xfailed.facet_col_wrap=2withmarginal_xgives one trendline per facet, none on the marginal row, and one legend entry.ruff checkandruff format --checkpass 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.