Skip to content

Marginal histograms ignore z/histfunc in density_heatmap/density_contour #5704

Description

@lucasjamar

Related to #3521 (closed as stale in 2024, reopening as a fresh issue per maintainer request).

For 2D histograms and contour plots, marginal histograms (marginal_x/marginal_y="histogram") always show raw bin counts, regardless of the z value and histfunc passed to density_heatmap/density_contour. The main plot correctly aggregates z via histfunc, but the marginal subplots do not.

Example:

import plotly.express as px
df = px.data.tips()

fig = px.density_heatmap(
    df, x="size", y="tip", z="total_bill", histfunc="sum",
    marginal_x="histogram", marginal_y="histogram",
)
fig.show()

Expected: the marginal histograms show the sum of total_bill per bin, matching the main heatmap.
Actual: the marginal histograms show raw row counts per bin.

I have a fix ready and will open a PR referencing this issue.

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