scale-x-time

Continuous x scale that formats axis labels as times of day.

Column values may be numeric seconds since midnight (an integer in [0, 86400)) or ISO-8601 strings of the form HH:MM[:SS]. Each break is converted via datetime(year: 2000, month: 1, day: 1, hour: 0, minute: 0, second: 0) + duration(seconds: int(n)) and rendered with dt.display(date-format); only the time portion of the pattern should be used.

Usage

scale-x-time(
  name: none,
  limits: none,
  breaks: auto,
  labels: auto,
  expand: auto,
  date-format: "[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 "[hour]:[minute]" Typst datetime.display pattern used for break labels.

Returns

Scale object consumed by plot.

Examples

Time-of-day axis using ISO-8601 HH:MM strings.

#let d = (
  (x: "08:00", y: 1),
  (x: "10:00", y: 4),
  (x: "12:00", y: 9),
  (x: "16:00", y: 16),
  (x: "20:00", y: 5),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-line(), geom-point(size: 2pt)),
  scales: (scale-x-time(),),
  width: 12cm,
  height: 6cm,
)

Line-and-point chart of five values peaking near 16:00 on a time-of-day x axis decoded from HH:MM strings.

Line-and-point chart of five values peaking near 16:00 on a time-of-day x axis decoded from HH:MM strings.

See also

scale-y-time, scale-x-datetime.

Back to top