Skip to main content

quiver

lq.quiver(x, y, directions, stroke=auto, scale=auto, pivot=end, tip=tiptoe.stealth.with(length: 400%), toe=none, color=black, map=color.map.viridis, min=auto, max=auto, norm="linear", label=none, z-index=2)(source)

Creates a quiver plot for visualizing vector fields over a rectangular coordinate grid.

The quiver function takes an array of xx- and yy-coordinates as well as a two-dimensional array of vector directions or a mapper from (x, y) pairs to direction vectors.

#lq.diagram(
lq.quiver(
lq.arange(-2, 3),
lq.arange(-2, 3),
(x, y) => (x + y, y - x)
)
)

By default, arrow lengths and strokes are scaled automatically to compensate for the density of a quiver plot.

On top, the arrows can easily be color-coded, similar to colormesh, see quiver.color.

Parameters

x : array

A one-dimensional array of xx data coordinates.

y : array

A one-dimensional array of yy data coordinates.

directions : array | function

Direction vectors for the arrows. This can either be

  • a two-dimensional array of dimensions m×nm×n where mm is the length of quiver.x and nn is the length of quiver.y,
  • or a function that takes two arguments (x, y) and returns a two-dimensional direction vector.

Masking is possible through nan values.

stroke : auto | stroke    default: auto

How to stroke the arrows. This parameter takes precedence over quiver.color. If the stroke thickness is left at auto, small arrows will be drawn with a thinner line style.

scale : auto | int | float    default: auto

Scales the length of the arrows uniformly. If set to auto, the length is heuristically computed from the density of the coordinate grid.

pivot : start | center | end    default: end

With which part the arrows should point onto the grid coordinates, e.g., when set to end, the tip (end) of the arrow will point to the respective coordinates.

Details
#show: lq.set-diagram(
xaxis: (tick-distance: 1),
xlim: (-3, 3),
ylim: (-3, 3),
width: 4cm
)

#let x = lq.arange(-2, 3)
#let y = lq.arange(-2, 3)
#let directions = lq.mesh(x, y, (x, y) => (x + y, y - x))

#lq.diagram(
title: [`pivot: end`],
lq.quiver(x, y, directions, pivot: end),
)
#lq.diagram(
title: [`pivot: center` (default)],
lq.quiver(x, y, directions, pivot: center),
)
#lq.diagram(
title: [`pivot: start`],
lq.quiver(x, y, directions, pivot: start),
)

tip : none | tiptoe.mark    default: tiptoe.stealth.with(length: 400%)

Determines the arrow tip to use. This expects a mark as specified by the tiptoe package.

toe : none | tiptoe.mark    default: none

Determines the arrow tail to use. This expects a mark as specified by the tiptoe package.

color : color | array | function    default: black

How to color the arrows. This can be a single color or a two-dimensional array with the same dimensions as quiver or a function that receives (x, y, u, v) tuples of x and y coordinates and corresponding direction components and returns a scalar (float) or color.

Details

In this example, we make a color-coding by taking the length of the direction vectors.

#lq.diagram(
lq.quiver(
lq.arange(-2, 3),
lq.arange(-2, 3),
(x, y) => (x + 2 * y, y - x),
color: (x, y, u, v) => calc.norm(u, v),
)
)

map : array | gradient    default: color.map.viridis

A color map to sample from. The color map can be given in form of a gradient or an array of colors.

min : auto | int | float    default: auto

Sets the data value that corresponds to the first color of the color map. If set to auto, it defaults to the minimum color value.

max : auto | int | float    default: auto

Sets the data value that corresponds to the last color of the color map. If set to auto, it defaults to the maximum color value.

norm : lq.scale | str | function    default: "linear"

The normalization method used to scale quiver.color scalars to the range [0,1][0,1] before mapping them to colors using the color map. This can be a scale, a string that is the identifier of a built-in scale or a function that takes one argument.

label : content    default: none

The legend label for this plot. See plot.label.

z-index : int | float    default: 2

Determines the zz position of this plot in the order of rendered diagram objects. See plot.z-index.