Skip to content

plotly/rainbow-colorscale

Rule rainbow-colorscale
Pack plotly
Severity warning
Fix none, edit by hand
Library versions every version

A rainbow colorscale such as Jet rises and falls in lightness, so it makes edges in the data that are not there. Use a scale whose lightness changes in one direction, such as Viridis.

fig = px.imshow(grid, color_continuous_scale="jet")
fig = go.Figure(go.Heatmap(z=grid, colorscale=px.colors.sequential.Turbo))
fig = px.imshow(grid, color_continuous_scale="Greys")
fig = go.Figure(go.Heatmap(z=grid, colorscale="Viridis"))

The rule reports the color scales Jet, Rainbow, Turbo and HSV, written as a string in upper or lower case with or without _r, or as an attribute of px.colors such as px.colors.sequential.Jet, when it is given to colorscale, color_continuous_scale or a setting that ends in _colorscale inside a plotly call, or assigned to px.defaults.color_continuous_scale.

The rule reports a scale where the code sets it, also on a color axis that no trace uses. The advice applies only when a trace colors numbers with the scale. A scatter plot without numeric colors, or without a reference to the color axis, does not show the scale.

xpd has no automatic fix, so make the change by hand.

The test of order is lightness. Each of the 94 named scales was resolved on a go.Heatmap and sampled at 21 even steps, and the CIELAB lightness of each step was computed, from 0 for black to 100 for white. A scale that changes direction draws a low and a high value equally dark.

Scale Changes of direction in lightness Reported
61 scales, such as "Greys", "Blues" and "Viridis" 0 no
Jet, which rose from 13.5 to 97.1 and fell back to 25.5 3 yes
HSV 3 yes
Rainbow 2 yes
Turbo, with its lightest color in the middle 1 yes
Blackbody, Bluered, Portland, Picnic 1, near one end or at a midpoint as the two-sided RdBu does no
Earth, mrybm, mygbm more than 0 no, because they appear in no file the rules were run on

px.imshow with "jet", a go.Scatter marker with "Jet" and update_layout(coloraxis_colorscale="Jet") all resolved to the same six stops. color_discrete_sequence is left alone, because it colors groups and not quantities. Numbers that name groups, such as cluster numbers, are better colored as categories, and the message says so. The rule has no fix, because the scale to use depends on whether the data has a midpoint.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

$S selects a spectrum colorscale. An unused coloraxis does not color any values. If a trace uses this scale for numeric color, its CIELAB lightness, 0 for black and 100 for white, rose from 13.5 to 97.1 and fell back to 25.5 along the scale, so the reader cannot tell a high value from a low one by how dark it is. Tufte writes that the mind's eye gives colors no visual order and that shades of gray show quantities better. Use "Greys", or a scale that gets darker with the value such as "Blues" or "Viridis". When the numbers name groups, such as clusters, color them as categories instead.

Browse the other rules of the plotly pack.