Skip to content

color_ramp

Color-ramp and classification helpers for data-driven vector symbology.

Mirrors packages/core/src/color-ramp.ts and the graduated/categorized stop-building in StylePanel.tsx so a choropleth built from Python produces the same vectorStyleStops the app would compute from the UI. The ramp names match VECTOR_COLOR_RAMPS exactly, so a ramp chosen here renders identically.

get_color_ramp

get_color_ramp(name: str) -> list[str]

Return a ramp's anchor colors, falling back to the default ramp.

Parameters:

Name Type Description Default
name str

A ramp name (e.g. "viridis").

required

Returns:

Type Description
list[str]

A fresh list of the ramp's anchor hex colors, or the default ramp's when

list[str]

name is unknown. A copy is returned so callers cannot mutate the

list[str]

shared VECTOR_COLOR_RAMPS entries.

interpolate_hex

interpolate_hex(start: str, end: str, ratio: float) -> str

Linearly interpolate between two #rrggbb colors.

Parameters:

Name Type Description Default
start str

Start hex color.

required
end str

End hex color.

required
ratio float

Blend factor in [0, 1].

required

Returns:

Type Description
str

The interpolated #rrggbb color.

interpolate_ramp_colors

interpolate_ramp_colors(name: str, count: int) -> list[str]

Sample a ramp into count evenly spaced colors (mirror of TS helper).

Parameters:

Name Type Description Default
name str

The ramp name.

required
count int

Number of colors to produce.

required

Returns:

Type Description
list[str]

count hex colors (a single end color when count <= 1).

equal_interval_breaks

equal_interval_breaks(minimum: float, maximum: float, count: int) -> list[float]

Build count evenly spaced breaks across [minimum, maximum].

quantile_breaks

quantile_breaks(values: list[float], count: int) -> list[float]

Build count quantile breaks from a numeric sample (mirror of TS helper).

graduated_stops

graduated_stops(values: list[Any], *, class_count: int = 5, color_ramp: str = 'viridis', classification_scheme: str = 'equal-interval') -> list[dict[str, Any]]

Build graduated vectorStyleStops from numeric values.

Mirrors createGraduatedStops in StylePanel.tsx: non-numeric values are dropped, breaks come from the chosen scheme, and colors are sampled from the ramp. The result is a list of {"value", "color"} stop dicts the app renders as an interpolate expression.

Parameters:

Name Type Description Default
values list[Any]

The column's raw values (non-numeric entries are ignored).

required
class_count int

Number of classes (clamped to at least 2).

5
color_ramp str

A ramp name from VECTOR_COLOR_RAMPS.

'viridis'
classification_scheme str

"equal-interval" or "quantile".

'equal-interval'

Returns:

Type Description
list[dict[str, Any]]

A list of {"value": float, "color": str} stops.

Raises:

Type Description
ValueError

If classification_scheme is not supported.