Repository navigation
Support marginal_x/marginal_y="heatmap" in density_heatmap/density_contour #5706
Description
Activity
@lucasjamar thank you for submitting this and opening a PR! If you don't mind adding an image too that would be great!
@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
@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?
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_contourfrom the scope of this work, and supporting marginal heatmaps only fordensity_heatmap.Two reasons:
px.density_heatmap()doesn't use color fills by default, so there's no extra synergy achieved by pairing marginal heatmaps withdensity_contourplots. At that point, you might as well allow marginal heatmaps for all plot types (which is another possibility!)- Possibly more important: Even if you do manually add fills to the
density_contourplot, colorbars forhistogram2dcontourtraces (which is whatdensity_contouruses under the hood) aren't compatible with heatmap colorbars. Heatmap colorbars are continuous, whilehistogram2dcontourcolorbars 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:
For reference, here's what the
histogram2dcontourcolorbar looks like normally: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!
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_contourfrom the scope of this work, and supporting marginal heatmaps only fordensity_heatmap.Two reasons:
px.density_heatmap()doesn't use color fills by default, so there's no extra synergy achieved by pairing marginal heatmaps withdensity_contourplots. At that point, you might as well allow marginal heatmaps for all plot types (which is another possibility!)- Possibly more important: Even if you do manually add fills to the
density_contourplot, colorbars forhistogram2dcontourtraces (which is whatdensity_contouruses under the hood) aren't compatible with heatmap colorbars. Heatmap colorbars are continuous, whilehistogram2dcontourcolorbars 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:
For reference, here's what the `histogram2dcontour` colorbar looks like normally:
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.
@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
For
density_heatmap/density_contour, it would be great to specify a heatmap as the marginal plot type as well: a single-row (formarginal_x) or single-column (formarginal_y) heatmap in the margins, colored by the same aggregate (z/histfunc) as the main plot, instead of a bar chart.Example:
Today
marginal_x/marginal_yonly support'rug','box','violin','histogram'.I have an implementation ready and will open a PR referencing this issue.