Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 73/ 160
04. Data Visualization & BI

Color Theory & Accessibility in Charts

Choose palettes that encode meaning and remain readable for color-vision deficiencies.

BeginnerPalettes · Contrast3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Pick colours that match what the numbers mean, make sure they can be told apart by people who see colours differently, and add labels or shapes as backup.

Think of it like…

Road signs: shape, colour and symbol all carry the message, so a driver who can't tell red from green still recognises a stop sign by its octagon and word.

Where you’ve seen it

A status dashboard marked on-track, at-risk and off-track using green, amber and red dots. About 1 in 12 male viewers can't reliably tell them apart, so the team keeps a blue-orange scheme with ▲ ● ▼ icons and text labels. The line chart with six series uses the Okabe-Ito colour-blind-safe palette (orange #E69F00, sky blue #56B4E9, bluish green #009E73, yellow #F0E442, blue #0072B2, vermillion #D55E00, reddish purple #CC79A7, black) plus direct labels at line ends instead of a legend. Grey axis text is darkened from #AAAAAA to #767676, which gives a 4.54:1 contrast ratio on white (just above the 4.5:1 target; #AAAAAA gives only about 2.3:1). A population heatmap switches from a rainbow colormap to viridis, so lightness increases monotonically with the value and the picture survives greyscale printing.

Words you’ll hear

Sequential, diverging, qualitative
The three palette types, matched to ordered, centred and categorical data.
Colour-vision deficiency (CVD)
Reduced ability to distinguish certain hues, most commonly red versus green.
Contrast ratio
(L1 + 0.05) / (L2 + 0.05) of relative luminances; WCAG targets 4.5:1 text and 3:1 graphics.
Perceptually uniform
A colormap where equal data steps look like equal visual steps (viridis, cividis).

Visual diagram

Loading interactive diagram

Theory & deep dive

Palettes that encode meaning

Use sequential colour for quantities that run from low to high: one hue with increasing darkness (Blues, Greens) or a perceptually uniform multi-hue map such as viridis, cividis or magma. Avoid rainbow/jet: its hue changes create false boundaries and its lightness is non-monotonic, so mid-range values look more important and greyscale prints become unreadable. Use diverging colour only when the data has a meaningful midpoint (change versus last year, variance to target, correlation), centre the neutral colour at that value (center=0, TwoSlopeNorm) and keep both arms equal in lightness. Use qualitative colour for unordered categories and keep the count to about 5 to 7; beyond that, use small multiples, grouping, direct labels or highlight one series in colour and grey the rest.

Colour should mean the same thing everywhere (if blue is "actual" on one chart, don't use it for "forecast" on the next), and semantic colours (green good, red bad) carry cultural assumptions and CVD issues; prefer blue and orange, or add icons. Limit saturation: use muted tones for context and one strong accent for the message. For the Python stack, Matplotlib offers viridis, cividis, coolwarm and RdBu; Seaborn offers color_palette("colorblind"), "flare", "vlag"; ColorBrewer and Viz Palette help design custom sets.

Same data, better palette

A 0–100 risk score shown with a rainbow map suggests sharp thresholds where none exist. The same data with viridis has monotonically increasing lightness, so higher risk always looks darker and the map still reads when printed in greyscale.

Key takeaway: Sequential for magnitude, diverging for centred deviation, qualitative for categories, and skip rainbow maps.

Accessibility: CVD, contrast and redundancy

About 8% of men and 0.5% of women have red-green colour-vision deficiency, and a smaller group has blue-yellow or total colour blindness, so test every palette with a simulator (Coblis, Color Oracle, colorspacious.cvd_space in Python). Safe qualitative sets include the Okabe-Ito palette (#E69F00, #56B4E9, #009E73, #F0E442, #0072B2, #D55E00, #CC79A7, black). Separate adjacent colours by lightness, not hue alone, since CVD mostly affects hue discrimination while lightness contrast is preserved, and check greyscale. Pair colour with other encodings: direct labels at line ends, different line styles or markers, patterns in bars, text values or icons in status cells.

Contrast is measured with relative luminance. For sRGB, linearise each channel (c ≤ 0.04045 ? c/12.92 : ((c + 0.055)/1.055)^2.4), compute L = 0.2126 R + 0.7152 G + 0.0722 B, and ratio = (L_lighter + 0.05)/(L_darker + 0.05). Mid-grey #767676 has L ≈ 0.181, so against white (L = 1) the ratio is 1.05 / 0.231 ≈ 4.54, just passing 4.5:1. WCAG asks 4.5:1 for normal text, 3:1 for large text and for graphical objects such as bars, lines and icons needed to understand content. Test dark mode separately (re-pick lightness, don't just invert), set a sufficient minimum line width and marker size, and write alt text or a data table for screen-reader users.

Checking a grey

#AAAAAA text on white has relative luminance ≈ 0.402, so contrast = 1.05 / 0.452 ≈ 2.3:1 (fails). Darkening to #767676 (L ≈ 0.181) gives 1.05 / 0.231 ≈ 4.54:1, which passes the 4.5:1 text guideline.

Key takeaway: Test with CVD simulators and contrast math, separate by lightness, and always add a redundant encoding.

How it works, step by step

Step 1 of 4
Designer

1. Classify the data

Decide if the colour channel encodes ordered values, deviation from a midpoint or unordered categories.

sequential · diverging · qualitative
Key numbers at this step
Midpoint?
only then diverge

When to use it & trade-offs

What it is

In charts, colour is an encoding and must be chosen by the data type it carries. Sequential palettes (light to dark of one hue, or perceptually uniform maps such as viridis) encode ordered magnitudes; diverging palettes (two hues meeting at a neutral midpoint) encode deviation from a meaningful centre such as zero or a target; qualitative palettes (distinct hues) encode unordered categories. Accessibility adds two constraints: colour-vision deficiency (CVD) affects roughly 8% of men and 0.5% of women (mostly red-green confusion), and contrast must be sufficient (WCAG recommends 4.5:1 for normal text and 3:1 for large text and graphical objects). The remedy is to never rely on colour alone.

Why it matters: Poor colour choices cause real misreadings: a rainbow map invents boundaries that aren't in the data, a red-green status scheme is unreadable for about one man in twelve, and light grey text on white fails everyone in poor lighting or on a projector. Accessible colour is also just better design: palettes with enough lightness contrast survive greyscale printing and dark mode, and redundant encodings (labels, shapes, icons) speed up reading for all viewers.

When to reach for it

  • Heatmaps, maps and any continuous colour scale
  • Status indicators and series colours in dashboards
  • Reports that will be printed, projected or viewed in dark mode

When to avoid or be careful

  • Rainbow and jet colormaps
  • Red versus green as the only status signal
  • Light grey text on a white background

Palette types

Sequential (viridis, single hue)
Best for: Ordered magnitudes such as density or risk score

Strengths: Lightness increases with value; greyscale-safe.

Watch out: Poor for showing deviation from a midpoint.

Diverging (blue-white-orange)
Best for: Change, variance and correlations around a centre

Strengths: Separates above and below the midpoint.

Watch out: Misleading if the midpoint isn't meaningful.

Qualitative (Okabe-Ito)
Best for: Unordered categories

Strengths: Distinct hues; CVD-safe sets exist.

Watch out: Breaks down beyond about 7–8 categories.

Interview signals & numbers to know

When this topic comes up

  • “Which colour palette should I use?”
  • “A colleague can't read the chart”
  • WCAG contrast
  • Colour-blind-safe palettes
  • Viridis versus jet

Benchmarks & rules of thumb

~8% / 0.5% -
men and women with red-green CVD
4.5:1 / 3:1 -
WCAG contrast targets for text and graphics
4.54:1 -
contrast of #767676 on white

Common mistakes & follow-ups

Common interview mistakes

  • Using a diverging palette for data with no meaningful centre.
  • Encoding category with hue and expecting people to remember 12 colours.
  • Testing only on your own monitor in light mode.

Likely interviewer follow-ups

  • Why is the rainbow colormap discouraged?
  • How do you make a status indicator accessible?
  • How would you check the contrast of text colours?
Interview tip: Quote one concrete contrast number (#767676 on white is 4.54:1) and the CVD prevalence. It shows accessibility is measured, not guessed.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Color Theory & Accessibility in Charts with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
KPI Cards & Executive Dashboard Design
Next topic
Avoiding Misleading Visuals & Chartjunk