Skip to main content

colorbar

lq.colorbar(plot, orientation="vertical", thickness=3mm, label=none, ..args)(source)

Creates a visual representation of the color mapping used in a plot instance like scatter or colormesh.

This generates a new (usually slim) diagram with a filled gradient according to the color map used in the plot, appropriate ticks, and optionally a label. This diagram can be configured through general set rules on diagram and through additional arguments passed through colorbar.args.

#show: lq.set-diagram(height: 3.5cm, width: 4cm)

#let mesh = lq.colormesh(
lq.linspace(-0.3, 1.3),
lq.linspace(-0.3, 1.3),
(x, y) => x * y,
map: gradient.linear(..color.map.icefire).sharp(9)
)

#lq.diagram(
mesh
)
#lq.colorbar(mesh, thickness: 2mm)

The color bar is a separate inline object and can be placed anywhere in the document. Note that if the example above were in code mode, Typst would place the color bar directly after the diagram with no space in-between. You can insert a manual space through h(.5em) (or similar).

Also, the color bar has a fixed length by default and does not know about the dimensions of the previous diagram. In order to guarentee the same height, it is advisable to use a set rule on diagram (as demonstrated above) to set the height for both the diagram and the color bar at once.

Parameters

plot : plot

A plot instance that uses color-coding, e.g., scatter, colormesh, contour, and quiver.

orientation : "vertical" | "horizontal"    default: "vertical"

How to orient the colorbar.

thickness : length    default: 3mm

The thickness of the colorbar.

label : content    default: none

A label to place on the axis.

..args : any

Additional arguments to pass to diagram.