Skip to main content

colorScaleByName()

function colorScaleByName(color): (x) => number[];

Returns a color scale function for a given colormap name.

Parameters

ParameterTypeDescription
colorstringName of the color scale (e.g., 'viridis', 'coolwarm_r').

Returns

A callable function that accepts a normalized value x ∈ [0, 1] and returns an RGB array.

(x): number[];

Parameters

ParameterType
xnumber

Returns

number[]

Remarks

This function is automatically generated for every color map and its reversed counterpart. For instance, both viridis and viridis_r can be used to generate forward or reversed colormap interpolators.

Example

const viridis = colorScaleByName('viridis');
const rgb = viridis(0.5); // [r, g, b]