Skip to content

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

Description

@lucasjamar

For density_heatmap/density_contour, it would be great to specify a heatmap as the marginal plot type as well: a single-row (for marginal_x) or single-column (for marginal_y) heatmap in the margins, colored by the same aggregate (z/histfunc) as the main plot, instead of a bar chart.

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="heatmap", marginal_y="heatmap",
)
fig.show()

Today marginal_x/marginal_y only support 'rug', 'box', 'violin', 'histogram'.

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

Activity

  1. robertclaus commented on Aug 17, 2026

    @robertclaus

    @lucasjamar thank you for submitting this and opening a PR! If you don't mind adding an image too that would be great!

  2. ghost added
    P3backlog
    on Aug 17, 2026
  3. lucasjamar commented on Aug 18, 2026

    @lucasjamar
    ContributorAuthor

    @lucasjamar thank you for submitting this and opening a PR! If you don't mind adding an image too that would be great!

    addressed in 789b082

  4. robertclaus commented on Aug 18, 2026

    @robertclaus

    @lucasjamar I meant an image in the PR description to show the feature. That commit doesn't seem to have an image if you meant something else?

  5. emilykl commented on Aug 20, 2026

    @emilykl
    Contributor

    Thanks for the issue and PR @lucasjamar! I think this is a reasonable feature request.

    Are you able to share some examples of the types of charts you're trying to create, or data you're trying to visualize? That would be helpful for discussion if you're able to share.

    I propose removing density_contour from the scope of this work, and supporting marginal heatmaps only for density_heatmap.

    Two reasons:

    1. px.density_heatmap() doesn't use color fills by default, so there's no extra synergy achieved by pairing marginal heatmaps with density_contour plots. At that point, you might as well allow marginal heatmaps for all plot types (which is another possibility!)
    2. Possibly more important: Even if you do manually add fills to the density_contour plot, colorbars for histogram2dcontour traces (which is what density_contour uses under the hood) aren't compatible with heatmap colorbars. Heatmap colorbars are continuous, while histogram2dcontour colorbars are discrete and place labels at the contour boundaries. This results in weird visual artifacts and a misleading colorbar when using the PR implementation (see screenshot below), and I'm not sure if there's a way to reconcile the two (although maybe it's possible).

    Code:

    fig = px.density_contour(
        df,
        x="total_bill",y="tip", 
        marginal_x="heatmap", marginal_y="heatmap"
    )
    fig.update_traces(
        selector=dict(type='histogram2dcontour'),
        contours_coloring="fill", 
    )
    fig.show()

    Screenshot:

    Image

    For reference, here's what the histogram2dcontour colorbar looks like normally:

    Image

    The implementation for density_heatmap, on the other hand, looks pretty reasonable and I'd be happy to have it as a feature.

    Let us know your thoughts!

  6. lucasjamar commented on Aug 23, 2026

    @lucasjamar
    ContributorAuthor

    Thanks for the issue and PR @lucasjamar! I think this is a reasonable feature request.

    Are you able to share some examples of the types of charts you're trying to create, or data you're trying to visualize? That would be helpful for discussion if you're able to share.

    I propose removing density_contour from the scope of this work, and supporting marginal heatmaps only for density_heatmap.

    Two reasons:

    1. px.density_heatmap() doesn't use color fills by default, so there's no extra synergy achieved by pairing marginal heatmaps with density_contour plots. At that point, you might as well allow marginal heatmaps for all plot types (which is another possibility!)
    2. Possibly more important: Even if you do manually add fills to the density_contour plot, colorbars for histogram2dcontour traces (which is what density_contour uses under the hood) aren't compatible with heatmap colorbars. Heatmap colorbars are continuous, while histogram2dcontour colorbars are discrete and place labels at the contour boundaries. This results in weird visual artifacts and a misleading colorbar when using the PR implementation (see screenshot below), and I'm not sure if there's a way to reconcile the two (although maybe it's possible).

    Code:

    fig = px.density_contour(
    df,
    x="total_bill",y="tip",
    marginal_x="heatmap", marginal_y="heatmap"
    )
    fig.update_traces(
    selector=dict(type='histogram2dcontour'),
    contours_coloring="fill",
    )
    fig.show()
    Screenshot:

    Image For reference, here's what the `histogram2dcontour` colorbar looks like normally: Image The implementation for `density_heatmap`, on the other hand, looks pretty reasonable and I'd be happy to have it as a feature.

    Let us know your thoughts!

    i see the issue, i therefore removed support and now its only density heatmap that is supported.

  7. lucasjamar commented on Aug 23, 2026

    @lucasjamar
    ContributorAuthor

    @lucasjamar I meant an image in the PR description to show the feature. That commit doesn't seem to have an image if you meant something else?

    done

  8. ghost closed this as completedin #5707on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions