scale-gradientn

N-colour continuous gradient colour/fill scale.

Interpolates through the colours array.

Usage

scale-gradientn(
  ..args,
)

Parameters

Parameter Default Description
..args Named arguments forwarded to the colour/fill scale.

Keys accepted by ..args:

  • colours: Array of colours interpolated in order from the low end of the domain to the high end; default () holds no colour, so pass at least two.
  • name: Axis or legend title, as a string or content; none (default) falls back to the mapped column name.
  • limits: Domain as a (lo, hi) pair, where either side may be auto to train that side from the data; none (default) trains both sides.
  • oob: Handling of rows outside limits: "drop" (default) removes them, "squish" clamps them to the nearest limit.
  • breaks: Array of tick positions in data units, a bare number for a single tick, a function of the trained values returning positions (the breaks-* helpers return such a function), or auto (default) for computed breaks.
  • labels: Array of labels aligned with the breaks, a function of the break value returning a string or content (the format-* helpers return such a function), or auto (default) to format each break.

Returns

Deferred scale spec consumed by scales.

Examples

Interpolate a numeric fill through several colours.

#let d = range(1, 8).map(i => (x: i, y: i, w: i))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", fill: "w"),
  layers: (geom-point(size: 5pt),),
  scales: scales(fill: scale-gradientn(
    colours: (rgb("#000000"), rgb("#888888"), rgb("#ffffff")),
  )),
  width: 10cm,
  height: 6cm,
)

Scatter chart of seven diagonal points whose fill interpolates through a black, grey, and white colour ramp.

Scatter chart of seven diagonal points whose fill interpolates through a black, grey, and white colour ramp.

See also

scales, scale-gradient, scale-gradient2.

Back to top