Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help


ax_vector_field (Fx, Fy, xvar, xlo, xhi, yvar, ylo, yhi) — Function

2D vector field (quiver) plot. Use inside ax_draw2d. Given a vector field F = (Fx(x,y), Fy(x,y)), samples on a grid and renders arrows showing the field direction and magnitude.

Examples

/* Rotation field */
ax_draw2d(ax_vector_field(-y, x, x, -3, 3, y, -3, 3))$

/* Source/sink */
ax_draw2d(
  ax_vector_field(x, y, x, -2, 2, y, -2, 2),
  title="Source"
)$

/* Direction-only (normalized arrows) */
ax_draw2d(
  ax_vector_field(-y, x, x, -3, 3, y, -3, 3),
  normalize=true, ngrid=25
)$

/* Phase portrait: vector field + streamlines */
ax_draw2d(
  color="#cccccc", ax_vector_field(-y, x, x, -3, 3, y, -3, 3),
  color="red", ax_streamline(-y, x, x, -3, 3, y, -3, 3),
  aspect_ratio=true, title="Phase Portrait"
)$

Relevant Options

OptionDefaultDescription
ngrid20Grid resolution (ngrid x ngrid arrows)
arrow_scale1.0Multiplier for arrow length
normalizefalseEqual-length arrows (direction only)
colorautoArrow color
nameautoLegend entry
opacity1.0Trace opacity

See also: ax_draw2d, ax_streamline