scale-colour-gradient

Continuous two-stop colour gradient.

Linearly interpolates between low and high across the trained domain. Defaults to a blue ramp.

Usage

scale-colour-gradient(
  low,
  high,
  name,
  limits,
  oob,
  breaks,
  labels,
)

Parameters

Parameter Default Description
low Colour for the low end of the domain.
high Colour for the high end of the domain.
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

Default low-to-high blue 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-gradient(),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points coloured by z along the default two-stop gradient ramp from dark navy at low to light sky-blue at high.

Scatter chart of twelve diagonal points coloured by z along the default two-stop gradient ramp from dark navy at low to light sky-blue at high.

Custom two-stop ramp passing explicit low and high colours.

#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-gradient(
    low: rgb("#fee5d9"),
    high: rgb("#a50f15"),
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points coloured by z along a custom two-stop ramp from pale peach at low values to deep crimson at high values.

Scatter chart of twelve diagonal points coloured by z along a custom two-stop ramp from pale peach at low values to deep crimson at high values.

See also

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

Back to top