Skip to content

plotly/heatmap-smoothing

Pack Severity Fix Versions
plotly info, and warning with style = "strict". A rule of the house style unsafe, with xpd check --fix --unsafe-fixes All versions

zsmooth blends the colors of neighboring cells, so the heatmap shows values the data does not hold. Pass zsmooth=False.

fig = go.Figure(go.Heatmap(z=grid, zsmooth="best"))
fig = go.Figure(go.Heatmap(z=grid, zsmooth=False))

The rule reports a zsmooth value that blends the colors of the cells.

Call Values reported
go.Heatmap "best", "fast"
go.Histogram2d, update_traces on a plotly figure "best"
go.Image that sets source "fast"

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes False.

"Above all else show the data" (page 92). Smoothing fills the space between the cells with colors that blend their values.

A 2 by 2 grid of 0 and 10 in "Greys", 400 by 400 pixels Colors drawn
go.Heatmap(zsmooth=False) 2
go.Heatmap(zsmooth="fast") 61
go.Heatmap(zsmooth="best") 252
go.Histogram2d(zsmooth="best") 252
go.Histogram2d(zsmooth="fast"), which resolved to False 2
go.Image(zsmooth="fast"), a checkerboard given as z 2
go.Image(zsmooth="fast"), the same pixels given as a PNG in source 61

The two colors of the data covered all 160,000 pixels without smoothing, and 45,156 and 40,401 pixels with it.

The rule reads "fast" on go.Heatmap only, and on go.Image only with source, because the docstring of go.Image says that zsmooth "only applies for image traces that use the source attribute". go.Image takes "fast" or False, and "best" raised ValueError. update_traces(zsmooth="fast") is left alone, because the rule cannot see which traces the figure holds.

The fix is unsafe, because the figure looks different when each cell is drawn as a block of one color.

The rule reports in code what these questions of the presentation guides (xpd charts, xpd tables, and xpd views) ask of the drawn display.

Question Page Principle What it asks
show-the-data 13 Show the data Does the chart show the observations themselves, avoiding cosmetic spline interpolation while overlaying any statistical trend smoother (such as LOESS or OLS) as a separate trace?
zsmooth=$S blends the colors of neighboring cells, so the heatmap shows values between the cells that the data does not hold. A 2 by 2 grid of 0 and 10 drew 252 colors with "best" and 61 with "fast", where zsmooth=False drew 2. Tufte asks above all else to show the data. Use zsmooth=False, which draws each cell in its own color.

See all rules in the plotly pack.