Overview
Palette provides named color sequences for data elements (scatter series, line series, bar groups, etc.). Palettes cycle infinitely using modulo indexing.
Palettes are separate from Theme, which controls plot chrome.
Usage
Colorblind-Safe Palettes
Palette::wong()
Bang Wong’s 8-color palette (Nature Methods 2011). Safe for all colorblind types.
Colors: #E69F00, #56B4E9, #009E73, #F0E442, #0072B2, #D55E00, #CC79A7, #000000
Palette::okabe_ito()
Alias for wong(). Same palette, widely known as Okabe-Ito.
Palette::tol_bright()
Paul Tol qualitative bright - 7 colors.
Palette::tol_muted()
Paul Tol qualitative muted - 10 colors.
Palette::tol_light()
Paul Tol qualitative light - 9 colors.
Palette::ibm()
IBM Design Language - 5 colors.
Palette::deuteranopia()
Safe for deuteranopia (red-green, most common ~6% males). Alias for wong().
Palette::protanopia()
Safe for protanopia (red-green). Alias for wong().
Palette::tritanopia()
Safe for tritanopia (blue-yellow, rare ~0.01%).
General-Purpose Palettes
Palette::category10()
Tableau 10 - 10 colors. Widely used in D3 and Matplotlib.
Palette::pastel()
Soft pastel colors - 8 colors.
Palette::bold()
Vibrant, saturated colors - 8 colors.
Custom Palettes
Palette::custom
Create a custom palette from a vector of color strings.
Palette name for identification
Vector of CSS color strings (hex or named)
Methods
len
Returns the number of colors in the palette.
is_empty
Returns true if the palette has no colors.
colors
Returns a slice of all color strings.
iter
Returns an infinite cycling iterator over colors.
Indexing
Palettes support modulo indexing:Accessibility
For colorblind-safe visualizations:- Use
wong(),tol_bright(), or condition-specific palettes - Combine color with other visual channels (shape, texture, size)
- Avoid red-green combinations for critical distinctions
- Add legends so colors are not the only information carrier
Source
src/render/palette.rs