Color Palettes
Color is an encoding, not decoration — matching the palette type (qualitative, sequential, diverging) to your data, with an eye on perception and accessibility.
Color is one of the most powerful channels in a chart — and one of the easiest to misuse. The single most important idea is this: the kind of palette you choose must match the kind of data it represents. Get that wrong and the colors will quietly tell a story the data never said.
Seaborn gives you three families of palettes for three kinds of data.
Three palette types for three kinds of data
- Qualitative palettes use distinct hues of roughly equal visual weight. They're for unordered categories (species, day, region), where no color should look "more" than another.
- Sequential palettes ramp a single hue from light to dark. They're for an ordered amount that runs low → high (counts, magnitude, density).
- Diverging palettes put two contrasting hues at the ends and a neutral color in the middle. They're for values with a meaningful midpoint (correlation around 0, change above/below a baseline).
The mismatch is the danger: a sequential ramp on unordered categories invents a ranking; a single-hue sequential map on signed data hides which side of zero you're on. Match the palette to the data and the color does honest work.
Qualitative: distinct colors for categories
When hue is a categorical column, Seaborn uses a qualitative palette. Pick
one with palette=:
No species should look bigger or more important than another, and a qualitative palette respects that — every hue carries equal weight.
Don't use a gradient for unordered groups
Coloring unordered categories with a sequential palette (a light-to-dark ramp) implies an order that isn't there — the reader will assume the dark category is "more" than the light one. Keep gradients for genuine amounts.
Sequential: a ramp for amounts
When hue is a continuous amount, a sequential palette maps small → light
and large → dark. Seaborn's rocket, mako, flare, and crest, plus
matplotlib's viridis, are all good choices:
Why viridis and rocket, not jet/rainbow
Good sequential palettes are perceptually uniform: equal steps in the
data look like equal steps in color, and lightness increases steadily so the
order is unmistakable (even in grayscale). The old jet/rainbow maps are
not — they have bright bands that read as ridges where the data is flat,
inventing structure. Prefer rocket, mako, viridis, magma.
Diverging: two directions from a center
When values spread out from a meaningful middle, a diverging palette gives each direction its own hue and marks the center as neutral. The classic case is a correlation matrix (centered at 0), which you met in the heatmaps chapter:
Strong positive correlations glow one color, strong negatives the other, and near-zero cells fade to neutral — the sign is readable at a glance precisely because the palette has a center.
Seeing the three side by side
sns.color_palette builds a palette and sns.palplot displays it, which
makes the three types easy to compare:
Notice the structure of each strip: the qualitative one jumps between unrelated hues; the sequential one marches steadily darker; the diverging one runs from one hue through a pale middle to another.
You're shading a heatmap of temperature anomalies (degrees above or below the long-run average, so the meaningful midpoint is 0). Which palette type fits?
Qualitative.
Sequential.
Diverging, centered at 0.
It doesn't matter; any palette works.
Designing your own and applying them
A few practical tools:
sns.color_palette("name", n)returns a list ofncolors you can reuse.sns.set_theme(palette="colorblind")sets the default palette for the whole session.sns.light_palette("seagreen"),sns.dark_palette(...), andsns.diverging_palette(220, 20)build custom sequential/diverging ramps.- For heatmaps, pass a colormap name to
cmap=(oras_cmap=Truewhen building a palette object).
Accessibility: don't rely on color alone
Roughly 1 in 12 men has some form of color-vision deficiency, most commonly trouble distinguishing red from green. Two habits keep your charts readable for everyone:
- Use a colorblind-safe palette — Seaborn ships one named
colorblind. - Never let color be the only cue. Back it up with
style(marker shape), direct labels, or facets, so the message survives in grayscale or for a colorblind reader.
When color stops working
- Too many categories. Beyond ~8–10 distinct hues, qualitative colors become hard to tell apart and impossible to match to a legend. Group rare categories, or facet instead of coloring.
- A rainbow map on continuous data. As noted, it manufactures false structure — use a perceptually uniform sequential map.
- A sequential map on signed data. It hides the sign — use diverging.
One question picks the palette
Before choosing colors, ask: is this color showing unordered groups, an amount, or a value around a center? The answer points straight at qualitative, sequential, or diverging — and rules the other two out.
Your turn
Using penguins, draw a scatter of bill_length_mm (x) vs
bill_depth_mm (y) with sns.relplot, colored by species using the
colorblind-safe qualitative palette:
hue="species",palette="colorblind".
Assign the result to g. (Species is an unordered category, so a
qualitative palette is the right type — and the colorblind one keeps it
readable for everyone.)
Check your understanding
Which kind of palette is appropriate for an unordered categorical
variable like region (North, South, East, West)?
Sequential.
Qualitative.
Diverging.
Any of them, since the data is categorical.
Why are palettes like viridis, rocket, and mako preferred over the
old jet/rainbow colormap for continuous data?
They use fewer colors, so they render faster.
They are perceptually uniform — equal data steps look like equal color steps, and lightness increases steadily, so they don't invent false structure.
They are the only palettes Seaborn supports.
They work only for categorical data.
Beyond picking a colorblind-friendly palette, what's the most robust way to keep a grouped chart readable for someone with color-vision deficiency?
Increase the figure's resolution.
Encode the group with a second channel too — e.g. marker style (shape), direct labels, or facets — so color isn't the only cue.
Use a darker background.
Add more colors so there's more variety.
You color a scatter's hue by a category that has 25 distinct values.
What's the likely problem?
Seaborn will refuse to draw more than 10 colors.
The hues become too similar to tell apart and to match against the legend, so the color encoding stops working.
The colors will automatically become a gradient.
Nothing — 25 categories color cleanly.
Color now works for you instead of against you. You've reached the end of the aesthetics tools — next we put everything together into the craft of telling a clear story with data.