skills/seaborn/references/palettes_and_theming.md
Qualitative, sequential, and diverging palettes, colorblind-safe choices, and theme, context, and style control.
Seaborn provides carefully designed color palettes for different data types:
Distinguish categories through hue variation:
"deep" - Default, vivid colors"muted" - Softer, less saturated"pastel" - Light, desaturated"bright" - Highly saturated"dark" - Dark values"colorblind" - Safe for color vision deficiencysns.set_palette("colorblind")
sns.color_palette("Set2")
Show progression from low to high values:
"rocket", "mako" - Wide luminance range (good for heatmaps)"flare", "crest" - Restricted luminance (good for points/lines)"viridis", "magma", "plasma" - Matplotlib perceptually uniformsns.heatmap(data, cmap='rocket')
sns.kdeplot(data=df, x='x', y='y', cmap='mako', fill=True)
Emphasize deviations from a midpoint:
"vlag" - Blue to red"icefire" - Blue to orange"coolwarm" - Cool to warm"Spectral" - Rainbow divergingsns.heatmap(correlation_matrix, cmap='vlag', center=0)
# Create custom palette
custom = sns.color_palette("husl", 8)
# Light to dark gradient
palette = sns.light_palette("seagreen", as_cmap=True)
# Diverging palette from hues
palette = sns.diverging_palette(250, 10, as_cmap=True)
set_theme() controls overall appearance:
# Set complete theme
sns.set_theme(style='whitegrid', palette='pastel', font='sans-serif')
# Reset to defaults
sns.set_theme()
Control background and grid appearance:
"darkgrid" - Gray background with white grid (default)"whitegrid" - White background with gray grid"dark" - Gray background, no grid"white" - White background, no grid"ticks" - White background with axis tickssns.set_style("whitegrid")
# Remove spines
sns.despine(left=False, bottom=False, offset=10, trim=True)
# Temporary style
with sns.axes_style("white"):
sns.scatterplot(data=df, x='x', y='y')
Scale elements for different use cases:
"paper" - Smallest (default)"notebook" - Slightly larger"talk" - Presentation slides"poster" - Large formatsns.set_context("talk", font_scale=1.2)
# Temporary context
with sns.plotting_context("poster"):
sns.barplot(data=df, x='category', y='value')