Color in Data Visualization
In a chart, color is not decoration - it is data. A map of temperature, a heatmap of activity, a set of plotted categories: each turns numbers into hue and lightness, and a careless choice of colormap can invent patterns that are not there or hide the ones that are. This is the interactive guide to encoding data with color honestly: the three scale types, why the rainbow misleads, and how to stay readable for every viewer.
Advanced visual encoding lab
The hard part of data visualization is not choosing a pretty palette; it is matching color to the structure of the data. This lab turns the whole decision into one instrument: task, scale type, baseline, binning, CVD simulation, outliers, opacity, legend design, and redundant labels all update the same chart and diagnostics.
Stress-test a colormap before it reaches a chart
A good visualization survives grayscale, color-vision deficiency, compression, noise, and real legends. Adjust the controls and watch the canvas report where the chart starts to lie: false boundaries, misplaced midpoint, weak category separation, missing redundancy, or an outlier that steals the entire dynamic range.
Encoding choice
Calculating...
Legend contract
Calculating...
Accessibility diagnosis
Calculating...
Export tokens
Calculating...
Perceptual order
False boundary risk
CVD resilience
Legend clarity
Category separation
Honesty score
Why color is data, not decor
The earlier articles in this library treated color as something to measure or to compose with. In data visualization it does a third job: it carries information. When a value is mapped to a color through a colormap (also called a color scale or palette), the reader runs that mapping in reverse to recover the data. If the mapping is ambiguous or uneven, the reader recovers the wrong numbers - and unlike a mislabeled axis, a bad colormap fails silently.
Two failures dominate. The first is using the wrong type of scale for the data - a rainbow for ordered magnitudes, or a sequential ramp for categories. The second is using a scale that is not perceptually uniform, so equal steps in the data do not look like equal steps in color. Both are avoidable with a little theory, and the demos here let you see each failure happen and then fix it.
The three scale types
Almost every honest colormap is one of three kinds. Choosing the right one is the single most consequential decision in coloring a chart.
| Scale | Use when data is… | How it looks | Example |
|---|---|---|---|
| Sequential | Ordered low → high, one direction | One hue, lightness ramps monotonically | Population density, temperature, counts |
| Diverging | Ordered around a meaningful midpoint | Two hues meeting at a neutral center | Profit vs loss, anomaly vs average, ±change |
| Categorical | Unordered groups / labels | Distinct hues, similar lightness | Countries, product lines, teams |
Map the same field through different scales
Below is one continuous data field rendered as a heatmap. Switch the colormap and watch how the same numbers tell different stories. A sequential map reads as smooth magnitude; a diverging map splits it around the middle; grayscale shows the raw ordering with no hue at all. The legend underneath is the key the reader uses to decode it.
Sequential scales
A sequential scale encodes data that runs from low to high in one direction: counts, density, magnitude, probability. The key property is that lightness must move monotonically - steadily darker or steadily lighter - because lightness is the channel the eye reads as "more." Hue may shift along the way (viridis travels purple → blue → green → yellow), but it is the relentless lightness ramp that makes the order legible, even in grayscale or for a colorblind viewer.
The classic mistake is a sequential scale whose lightness is not monotonic, so two different values map to the same apparent brightness and become indistinguishable. The good modern defaults - viridis, magma, cividis - are engineered specifically to keep lightness rising at a near-constant rate.
Diverging scales
A diverging scale is for data with a meaningful midpoint - zero, an average, a target, a baseline. It uses two contrasting hues (classically blue and red) that grow more saturated and darker as values move away from a neutral, light center. The center is the anchor: it must sit on the value that actually matters, or the chart lies.
Move the neutral point and watch the story change
Each cell is a region's change versus a baseline, colored on a blue-white-red diverging scale. Drag the midpoint: where you place the neutral white decides which regions read as "good" (blue) and which as "bad" (red). Putting the midpoint anywhere but the true reference value manufactures a conclusion - the most common diverging-scale abuse.
Categorical scales
A categorical (qualitative) scale encodes unordered groups, so its colors must look equally weighted - distinct in hue but similar in lightness and saturation, so none jumps out as "more important" or "higher." The hard limit is how many colors a reader can reliably tell apart: beyond roughly eight, distinct hues start to collide and the legend becomes a memory test. Past that, switch to direct labels, grouping, or small multiples instead of more colors.
The rainbow problem
For decades the default heatmap colormap was jet - the rainbow from blue through cyan, green, and yellow to red. It looks vivid and "scientific," and it is one of the most criticized choices in all of visualization. Jet is not perceptually uniform: its lightness rises and falls instead of climbing steadily, so it has bright ridges at cyan and yellow and dark valleys at blue and red. Those ridges read as edges - boundaries the data never contained - while the dark ends crush real detail.
The same data in a bad map and a good one
Both panels show the identical continuous field - left in jet, right in viridis. Now press Show lightness only: each map is replaced by the brightness the eye actually perceives. Viridis becomes a smooth ramp (its lightness is monotonic), while jet turns into lumpy bands - proof that it invents light/dark structure the data does not have. That is exactly what misleads a reader.
Jet (rainbow)
Bright ridges at cyan/yellow = false boundaries
Viridis (perceptual)
Monotonic lightness = honest magnitude
Colorblind-safe palettes
Around 8% of men and 0.5% of women have a color-vision deficiency, most commonly red-green. A categorical palette that relies on telling red from green - or any two hues that collapse together under CVD - excludes a large slice of your audience. The fix is to choose colors that stay distinct after simulation and to lean on lightness differences, which survive every type of CVD.
Simulate CVD and see which series collide
Pick a categorical palette, then simulate a color-vision deficiency. The swatches re-render as that viewer would see them, and the checker flags any two series that become too similar to distinguish. Compare the generic bright palette with the Okabe-Ito set, which was designed to stay separable under all common deficiencies.
Legends and redundant encoding
A colormap is only half a chart; the legend is the other half - the key that turns colors back into numbers. A continuous scale needs a continuous color bar with labeled values; a categorical scale needs an unambiguous swatch-to-label mapping, ideally placed near or directly on the marks it describes. A beautiful colormap with a missing or mislabeled legend is unreadable.
The most robust safeguard is redundant encoding: never let color be the only carrier of meaning. Pair it with direct labels, shapes, line styles, position, or text. If your chart still works when printed in grayscale or seen by a colorblind reader, color has become an enhancement rather than a single point of failure - which is exactly where you want it.
Practical guidelines
From theory to code
In practice a colormap is a function from a normalized value in [0, 1] to a color. You normalize the data to that range, then look the value up in the scale - either by interpolating between a handful of control colors or by indexing a precomputed table. The crucial detail is where you interpolate: blending two colors in raw sRGB often passes through a muddy or dark middle, so good libraries interpolate in a perceptual space such as Oklch or Lab, which keeps the ramp smooth and the lightness honest.
Modern toolchains make this routine: charting libraries ship viridis and ColorBrewer scales built in, and CSS now interpolates gradients in perceptual spaces with in oklch. The takeaway is the same in every environment - normalize, map through a perceptual scale, and label the result with a legend.
Pitfalls and gotchas
Test your understanding
Six questions on scale types, perceptual uniformity, and accessibility. Instant feedback, no scores recorded - a wrong answer comes with a short explanation.
Quick check
Continue your journey
Data-visualization color draws on the palette-building, accessibility, and perceptual articles around it. The numbers reflect each article's position in the editorial roadmap.
Color Psychology and the Meaning of Color
Why conventions like red=danger, green=go carry into every chart.
Design · 24Color Theory and Harmony
Where your categorical and accent colors come from in the first place.
Vision · 07Color Blindness and Color Vision Deficiency
The science behind the CVD simulation that vets every chart palette.
Design · 13Accessible Color Design and WCAG Contrast
Legends and labels still have to meet contrast - here is how.
Colorimetry · 22Oklab and Oklch: Modern Perceptual Color Spaces
The space where perceptual colormaps like viridis are built and interpolated.
Colorimetry · 20ΔE Metrics from CIE76 to CIEDE2000 and ΔEITP
How "too similar to tell apart" is actually measured between two colors.
Digital · 21HSL, HSV, and HSB: The Cylindrical Color Models
The quick model for spinning out categorical hues by angle.