You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: histogram2dcontour uses wrong fill colors for negative values #8005
histogram2dcontour traces use incorrect fill colors when bin values are negative.
Negative bin values can occur when histfunc is set to 'avg', 'min', or 'max', and the input z array contains negative values.
When some bin values are negative, all negative bin values are filled with the same color as 0 on the colorscale, while the outermost fill level is filled with the same color as the lowest number on the colorscale.
constx=[1,2,3,4,1,2,3,4];consty=[1,1,1,1,2,2,2,2];// The bug is triggered when histfunc is 'avg', 'min', or 'max',// and some z-values are negative such that some resulting bin values// end up negative// This example uses all-negative z values to show the most extreme// case, but not all z-values need to be negative to trigger the bugconstz=[-10,-50,-100,-150,-10,-50,-100,-150];Plotly.newPlot('div1',[{type: 'histogram2dcontour',x: x,y: y,z: z,histfunc: 'avg',// or 'min' or 'max'contours: {coloring: 'fill',showlabels: true,},}],{title: {text: 'histogram2d contour plot: wrong fill colors!',subtitle: {text: 'Compare contour labels on plot to colorscale'}}});
Screenshot:
Expected behavior
Contour fills should match fill colors indicated by colorscale
histogram2dcontour never coerces contours.type, so the closeBoundaries switch matches neither case and prefixBoundary stays unset.
Empty edge bins read as 0, so only levels below 0 need that prefix. #8088 switches on contours.type || 'levels'; levels is the attribute default.
New test in contour_test.js uses this issue's repro and checks prefixBoundary on every fill level.
Per your PR (and my review), contours.type is not coerced. This seems like a bug that should be fixed rather than worked around. What do you think of updating histogram2dcontour/defaults.js to take care of this?
Activity
jamalkamaladdin commentedon Sep 28, 2026
histogram2dcontour never coerces contours.type, so the closeBoundaries switch matches neither case and prefixBoundary stays unset.
Empty edge bins read as 0, so only levels below 0 need that prefix.
#8088 switches on contours.type || 'levels'; levels is the attribute default.
New test in contour_test.js uses this issue's repro and checks prefixBoundary on every fill level.
camdecoster commentedon Sep 29, 2026
Per your PR (and my review),
contours.typeis not coerced. This seems like a bug that should be fixed rather than worked around. What do you think of updatinghistogram2dcontour/defaults.jsto take care of this?