element-rect

Rectangle element: fill and stroke.

Pass the result to theme under keys like panel-background.

Usage

element-rect(
  fill: none,
  stroke: none,
)

Parameters

Parameter Default Description
fill none Rectangle fill colour, or none to inherit.
stroke none Rectangle stroke, or none to inherit.

Returns

Element dictionary consumed by theme.

Examples

Tinted panel background via theme.

#let d = range(0, 10).map(i => (x: i, y: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  theme: theme(panel-background: element-rect(fill: rgb("#f7f0e7"))),
  width: 10cm,
  height: 6cm,
)

Scatter plot of y against x with the panel background tinted warm cream via element-rect on the panel-background surface.

Scatter plot of y against x with the panel background tinted warm cream via element-rect on the panel-background surface.

Add a stroke to frame the panel as well as fill it.

#let d = range(0, 10).map(i => (x: i, y: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  theme: theme(panel-background: element-rect(
    fill: rgb("#fff7e6"),
    stroke: 1pt + rgb("#cc7a00"),
  )),
  width: 10cm,
  height: 6cm,
)

Scatter plot of y against x with a cream-filled panel ringed by a 1pt amber stroke via element-rect fill and stroke.

Scatter plot of y against x with a cream-filled panel ringed by a 1pt amber stroke via element-rect fill and stroke.

See also

theme, element-text, element-line, element-blank.

Back to top