Colors
The colors library provides functions for color manipulation, color space conversion, and color palettes.
Functions
Color(input: string)
Convert a color string or named color into a canonical sRGB tuple.
The output is a tuple of 3 or 4 numbers between 0 and 1, representing the red, green, blue, and optional alpha components.
Supports various formats:
- Hex:
#rgb,#rrggbb,#rrggbbaa(e.g.'#f00','#ff0000','#ff000080') - RGB/RGBA:
rgb(r, g, b),rgba(r, g, b, a)(e.g.'rgb(255, 0, 0)','rgba(255, 0, 0, 0.5)') - HSL:
hsl(h, s%, l%),hsla(h, s%, l%, a)(e.g.'hsl(0, 100%, 50%)') - OKLCH:
oklch(l%, c, h),oklch(l%, c, h / a)(e.g.'oklch(50% 0.3 240)') - Named colors: From the
NAMED_COLORSpalette (see below)
["Color", "'#f00'"]
// ➔ ["Tuple", 1, 0, 0]
["Color", "'rgba(255, 0, 0, 0.5)'"]
// ➔ ["Tuple", 1, 0, 0, 0.5]
["Color", "'red'"]
// ➔ ["Tuple", 0.843, 0.09, 0.043]
["Color", "'blue'"]
// ➔ ["Tuple", 0.051, 0.502, 0.949]
Named Colors
The Color function supports a comprehensive palette of named colors from the NAMED_COLORS object:
| Color Name | Swatch | Color Name | Swatch |
|---|---|---|---|
red | orange | ||
yellow | lime | ||
green | teal | ||
cyan | blue | ||
indigo | purple | ||
magenta | black | ||
white | dark-grey | ||
grey | light-grey | ||
brown | olive | ||
midnight | sky | ||
carbon | charcoal | ||
slate | graphite | ||
stone | ash | ||
mist | snow |
Colormap(name: string)
Colormap(name: string, n: number)
Colormap(name: string, t: number)
Sample colors from a named palette.
- If only a name is provided, returns the full list of colors in the palette.
- If an integer
n≥ 2 is provided, returnsnevenly-spaced colors. - If a real number
tbetween 0 and 1 is provided, returns the color at positiont.
["Colormap", "'viridis'", 5]
Available Palettes
Sequential
These palettes are perceptually uniform and suitable for ordered data.
Each sequential palette also has a -reversed variant (e.g., viridis-reversed).
| Name | |
|---|---|
viridis | |
inferno | |
magma | |
plasma | |
turbo | |
cividis | |
rocket | |
mako | |
grey |
Diverging
These palettes are symmetric around a neutral midpoint.
Each diverging palette also has a -reversed variant (e.g., roma-reversed).
| Name | |
|---|---|
roma | |
rdbu | |
coolwarm | |
vik | |
broc | |
ocean-balance |
Categorical
These palettes are designed for discrete, non-ordered categories.
| Name | |
|---|---|
tycho11 | Default categorical palette. Provides very good perceptual separation for up to 8 colors. |
tycho-dark11 | A variant of Tycho 11 optimized for dark backgrounds. |
tycho-robust11 | Reinforced variant that improves separability under color vision deficiency and low-contrast environments. |
tycho-soft11 | Low-contrast palette with soft tones, ideal for filled areas and dashboards. Less suitable for thin lines. |
tycho-soft-dark11 | Soft-contrast palette optimized for charcoal backgrounds, suitable for both lines and filled surfaces. |
tycho-bold11 | High-contrast palette with strong separation, ideal for thin lines and dense line charts. |
tycho-bold-dark11 | Energetic, high-contrast palette for dark UI, providing strong structural consistency for thin strokes. |
tableau10 | The classic Tableau 10 palette, also used as the default in Matplotlib. |
mathematica10 | Palette inspired by the default colors used in Wolfram Mathematica. |
cupertino10 | Apple system palette optimized for light appearance. |
cupertino-dark10 | Apple system palette optimized for dark appearance. |
kelly22 | Set of 22 colors maximized for contrast, suitable for datasets with a large number of categories. |
spectrum12 | Balanced palette of 12 colors covering the full visible spectrum. |
ColorToColorspace(color, colorspace: string)
Convert a color to its components in a specified color space.
Supported color spaces: "rgb", "hsl", "oklch", "oklab".
["ColorToColorspace", "'red'", "'hsl'"]
// ➔ ["Tuple", 0, 1, 0.5]
ColorFromColorspace(components: tuple, colorspace: string)
Convert components from a specified color space back to a canonical sRGB tuple.
["ColorFromColorspace", ["Tuple", 0, 1, 0.5], "'hsl'"]
// ➔ ["Tuple", 1, 0, 0]