RunMat
GitHub

quiver — Visualize 2-D vector fields with quiver plots in MATLAB and RunMat.

quiver visualizes 2-D vector fields as arrows anchored at data points. Supported call forms, scaling behavior, and returned handle semantics follow MATLAB behavior.

Syntax

h = quiver(U, V)
h = quiver(X, Y, U, V)
h = quiver(X, Y, U, V, LineSpec)
h = quiver(X, Y, U, V, Name, Value, ...)
h = quiver(ax, U, V)
h = quiver(ax, X, Y, U, V)
h = quiver(ax, X, Y, U, V, LineSpec)
h = quiver(ax, X, Y, U, V, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
UNumericArrayYesVector field x-components.
VNumericArrayYesVector field y-components.
XNumericArrayYesX coordinates (vector or matrix).
YNumericArrayYesY coordinates (vector or matrix).
lineSpecStyleSpecYesLine style/color shorthand.
propsAnyVariadicName/value quiver style properties.
axAxesHandleYesTarget axes handle.

Returns

NameTypeDescription
hNumericScalarHandle to the rendered quiver plot.

Errors

IdentifierWhenMessage
RunMat:quiver:InvalidArgumentInput data, axes targeting, or quiver style arguments are invalid.quiver: invalid argument
RunMat:quiver:InternalInternal quiver construction or rendering fails unexpectedly.quiver: internal operation failed

How quiver works

  • quiver(U, V) builds the default coordinate grid from the shape of U and V.
  • quiver(X, Y, U, V) accepts explicit coordinate vectors or meshgrid-style axes, depending on the input layout.
  • The returned value is a quiver-handle object that can be queried and updated through get and set.
  • Auto-scale factor, head size, line width, color, and display-name workflows are all part of the plotting property path.
  • Dedicated GPU geometry generation keeps vector-field rendering on device when plotting-compatible buffers are available.

Options

  • 'AutoScaleFactor' / 'Scale' controls arrow scaling.
  • 'MaxHeadSize' / 'HeadSize' controls the size of arrowheads.
  • Line-style color and width workflows are supported through the same style parsing and handle/property path used by other line-like plots.

Does RunMat run quiver on the GPU?

The direct quiver path emits renderer-ready arrow geometry from GPU buffers on the happy path.

Axes-local state, handle/property workflows, and replay/export behavior stay aligned across GPU and fallback rendering paths.

GPU memory and residency

quiver preserves GPU residency on the direct path by building arrow geometry from exported GPU buffers. If the direct geometry path is unavailable for the active input combination, RunMat falls back while preserving the same quiver semantics and handle behavior.

Examples

Create a vector field from U and V only

[X, Y] = meshgrid(-2:0.5:2, -2:0.5:2);
U = -Y;
V = X;
quiver(U, V);

Expected output:

% RunMat infers the coordinate grid from the vector-field shape

Provide explicit coordinates for a flow field

[X, Y] = meshgrid(-2:0.5:2, -2:0.5:2);
U = -Y;
V = X;
quiver(X, Y, U, V);

Adjust arrow scaling and head size through the handle

[X, Y] = meshgrid(-2:0.5:2, -2:0.5:2);
U = -Y;
V = X;
h = quiver(X, Y, U, V);
set(h, 'AutoScaleFactor', 1.5, 'MaxHeadSize', 0.2, 'DisplayName', 'rotation');
legend;

Gradient vector field over a scalar potential

[X, Y] = meshgrid(linspace(-2, 2, 25), linspace(-2, 2, 25));
Z = X .* exp(-X.^2 - Y.^2);
[DX, DY] = gradient(Z, X(1,2)-X(1,1), Y(2,1)-Y(1,1));

contourf(X, Y, Z, 15);
hold on;
quiver(X, Y, DX, DY, 'k', 'LineWidth', 1);
hold off;

colormap('turbo');
colorbar;
title('Gradient Field over Scalar Potential');
xlabel('x');
ylabel('y');
Expected output:
Gradient vector field over a scalar potential

Using quiver with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how quiver changes the result.

Run a small quiver example, explain the result, then change one input and compare the output.

FAQ

How do I control arrow lengths in a quiver plot?

Use the 'AutoScaleFactor' property. A value of 1 means default scaling, 0 disables auto-scaling entirely (arrows drawn at raw data magnitude), and values like 1.5 or 2 make arrows proportionally longer.

h = quiver(X, Y, U, V);
set(h, 'AutoScaleFactor', 0); % raw magnitudes, no auto-scaling
Can I overlay quiver arrows on top of a contourf plot?

Yes. Plot the filled contour first, then call hold on and add the quiver layer. Both share the same axes, so the coordinate grids align automatically.

contourf(X, Y, Z);
hold on;
quiver(X, Y, U, V, 'Color', 'k');
Does RunMat support 3-D quiver plots?

Not yet. quiver currently handles 2-D vector fields only. For 3-D direction visualization, consider using plot3 to draw line segments manually, or combine scatter3 with custom arrow geometry.

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · polarplot · print · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how quiver is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.