Skip to content

[BUG]: density_heatmap marginal heatmaps ignore histnorm #5932

Backlog

Description

@pinjun99

Description

With marginal_x="heatmap" / marginal_y="heatmap" (added in #5707), the marginal strips copy histfunc from the main heatmap but not histnorm. All three traces share coloraxis, and the hover label even says percent, but the marginal strips still use raw counts. The shared colour scale therefore mixes percentages and counts.

This is the histnorm counterpart of #5704, which covered marginal histograms ignoring z/histfunc.

Screenshots/Video

Not applicable. The mismatch is in the trace histnorm values (and therefore the shared colour scale), which the steps below print directly.

Steps to reproduce

Reproduced on current main (2b5fddb50), which is ahead of the latest PyPI release.

import plotly.express as px

fig = px.density_heatmap(
    x=[0, 0, 1], y=[0, 1, 1], histnorm="percent",
    marginal_x="heatmap", marginal_y="heatmap",
)
print([trace.histnorm for trace in fig.data])

Output on main (2b5fddb50):

['percent', None, None]

Expected: ['percent', 'percent', 'percent']. The same gap appears with histnorm="probability" and the other histnorm values.

Notes

heatmap_trace_patch in plotly/express/_core.py sets histfunc=args.get("histfunc") but does not set histnorm. Adding histnorm=args.get("histnorm") next to it fixes it. I can open a PR with a regression test in tests/test_optional/test_px/test_marginals.py.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions