scale-colour-gradientn

Continuous n-stop colour gradient.

Walks colours as a sequence of stops and linearly interpolates between adjacent stops. Useful for ramps that require more than two anchor colours (for example a ColorBrewer palette used as a continuous ramp).

Usage

scale-colour-gradientn(
  colours,
  name,
  limits,
  oob,
  breaks,
  labels,
)

Parameters

Parameter Default Description
colours Array of two or more colours.
name Legend title. Overrides any name set via labels when both are present.
limits Pair (lo, hi) clipping the trained domain, or none.
oob Out-of-range policy: "drop" (default) removes rows whose value falls outside limits; "squish" clamps continuous values to the nearest endpoint.
breaks Array of break values for the legend, or auto.
labels Array of legend labels aligned with breaks, or auto.

Returns

Scale object consumed by plot.

Examples

Three-stop ramp interpolating green-yellow-red across the domain.

#let d = range(0, 12).map(i => (x: i, y: i, z: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "z"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-gradientn(colours: (
    rgb("#1a9850"), rgb("#ffffbf"), rgb("#d73027"),
  )),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points coloured by z along a custom three-stop n-stop ramp passing green through pale yellow to red.

Scatter chart of twelve diagonal points coloured by z along a custom three-stop n-stop ramp passing green through pale yellow to red.

Feeding a brewer palette into scale-colour-gradientn lifts a discrete palette into a continuous ramp.

#let d = range(0, 12).map(i => (x: i, y: i, z: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "z"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-gradientn(
    colours: brewer-palette("RdYlBu"),
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points coloured by z along an n-stop ramp built from the ColorBrewer RdYlBu palette running red through yellow to blue.

Scatter chart of twelve diagonal points coloured by z along an n-stop ramp built from the ColorBrewer RdYlBu palette running red through yellow to blue.

See also

scale-colour-gradient, scale-colour-gradient2, scale-fill-gradientn.

Back to top