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(
  ..args,
)

Parameters

Parameter Default Description
..args

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