scale-y-datetime

Continuous y scale that formats axis labels as datetimes.

Column values may be numeric seconds since 2000-01-01T00:00:00 or ISO-8601 strings of the form YYYY-MM-DDTHH:MM[:SS] or YYYY-MM-DD HH:MM[:SS].

Usage

scale-y-datetime(
  name: none,
  limits: none,
  breaks: auto,
  labels: auto,
  expand: auto,
  date-format: "[year]-[month repr:numerical]-[day] [hour]:[minute]",
)

Parameters

Parameter Default Description
name none Axis title. Overrides any name set via labs when both are present.
limits none Pair (lo, hi) clipping the trained domain (in seconds), or none for automatic limits.
breaks auto Array of break values (in seconds), or auto for automatic tick selection.
labels auto Array of tick labels aligned with breaks, or auto.
expand auto Padding around the domain. Accepts a ratio (5%) for proportional breathing room, a length (5pt) for canvas-space padding, a relative (5pt + 5%) for both, or a (lo, hi) 2-tuple for asymmetric padding. auto keeps the per-scale default; false collapses to zero.
date-format "[year]-[month repr:numerical]-[day] [hour]:[minute]" Typst datetime.display pattern used for break labels.

Returns

Scale object consumed by plot.

Examples

Datetime axis on the y, useful for laying out events along a vertical timeline.

#let d = range(0, 6).map(i => (
  x: i,
  y: "2024-04-01T0" + str(8 + i) + ":00",
))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-y-datetime(date-format: "[hour]:[minute]"),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of six points climbing a y axis whose ticks show hour-minute decoded from ISO-8601 datetime strings.

Scatter chart of six points climbing a y axis whose ticks show hour-minute decoded from ISO-8601 datetime strings.

See also

scale-x-datetime, scale-y-date.

Back to top