ferrum.color¶
Programmatic access to ferrum's color palettes — categorical, sequential, and diverging.
Programmatic access to ferrum's color palettes.
Provides functions to retrieve hex color arrays from named categorical, sequential, and diverging palettes. Categorical palettes mirror the Rust palette registry; sequential/diverging palettes interpolate using the same stop definitions as the Rust renderer.
palette ¶
Return hex colors from a named palette.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Palette name (e.g., "tableau10", "okabe_ito", "viridis"). |
required |
n
|
int
|
Number of colors. For categorical palettes, wraps cyclically if n exceeds the palette length. For continuous palettes, interpolates n evenly-spaced colors. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Hex color strings (e.g., |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognized palette. |
Examples:
to_hex ¶
Convert a color to a hex string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
tuple or str
|
An RGB tuple with values in [0, 1] (floats) or [0, 255] (ints), or a hex string (returned as-is after normalization). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hex string like |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input format is not recognized. |
Examples:
sequential ¶
Return n interpolated colors from a sequential palette.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Sequential palette name (e.g., "viridis", "plasma", "magma", "inferno", "cividis", "blues", "cool_blue", "warm_ochre", "night_blue", "electric_lime", "signal_blue", "ember_orange"). |
required |
n
|
int
|
Number of interpolated colors. |
256
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Hex color strings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognized sequential palette. |
Examples:
diverging ¶
Return n colors from a diverging palette, centered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Diverging palette name (e.g., "rdbu", "blue_to_red", "cyan_to_amber", "blue_to_violet"). |
required |
n
|
int
|
Number of colors (odd recommended for a distinct center point). |
11
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Hex color strings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a recognized diverging palette. |
Examples: