Skip to content

Support marginal_x/marginal_y="heatmap" in density_heatmap/density_contour - #5707

Open
lucasjamar wants to merge 1 commit into
plotly:mainfrom
lucasjamar:marginal-heatmap-feature
Open

Support marginal_x/marginal_y="heatmap" in density_heatmap/density_contour#5707
lucasjamar wants to merge 1 commit into
plotly:mainfrom
lucasjamar:marginal-heatmap-feature

Conversation

@lucasjamar

Copy link
Copy Markdown

Summary

  • Adds 'heatmap' as a supported marginal_x/marginal_y value for density_heatmap/density_contour, drawing a single-row (marginal_x) or single-column (marginal_y) heatmap strip in the margin, colored by the same z/histfunc aggregate as the main plot (or raw count when z isn't given).
  • Implemented as a go.Histogram2d trace reusing the real perpendicular-axis column, collapsed to a single explicit bin (via computed xbins/ybins edges — nbins*=1 alone isn't reliable since plotly.js's "nice number" bin-sizing can still round to 2 bins). Binning happens client-side, same as the main trace.
  • Shares the main plot's coloraxis/colorbar (coloraxis1) rather than drawing its own. For density_contour, whose main trace is lines-only (contours.coloring="none") and has no existing coloraxis, coloraxis1 is now built (from a default colorscale — density_contour has no color_continuous_scale argument) whenever a heatmap marginal is requested, without changing the main contour trace's own appearance.
  • Restricted to density_heatmap/density_contour — raises a clear ValueError on scatter/histogram/ecdf.
  • Fixes two related bugs surfaced while testing: (1) the existing marker-color post-processing for marginals would crash on go.Histogram2d (no marker property), (2) density_contour's discrete color-grouping (line.color) update would crash when a go.Histogram2d marginal trace is present in the same group.

Fixes #5706

Test plan

  • Added test_marginal_heatmap_uses_z_and_histfunc, test_marginal_heatmap_without_z, test_marginal_heatmap_unsupported_chart_type_raises, test_marginal_heatmap_with_discrete_color in tests/test_optional/test_px/test_marginals.py
  • pytest tests/test_optional/test_px/test_marginals.py — 149 passed
  • pytest tests/test_optional/test_px/ — 1139 passed, 3 skipped, 4 xfailed (47 pre-existing failures in test_trendline.py unrelated to this change — local statsmodels/scipy version conflict)
  • ruff check clean on changed files (pinned ruff==0.11.12)
  • Manually verified in-browser: single clean row/column strips (no double-row rendering), correct shared colorbar label/scale for both histfunc="sum" and histfunc="avg", and the density_contour + discrete color + heatmap marginal crash scenario

…ntour

Draws a single-row/column heatmap strip in the margin, colored by the
same z/histfunc aggregate as the main plot, sharing its coloraxis.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

Support marginal_x/marginal_y="heatmap" in density_heatmap/density_contour

1 participant