quiver
Load sample data that represents air currents over North America. For this example, select a subset of the data.
load('wind','x','y','u','v') X = x(11:22,11:22,1); Y = y(11:22,11:22,1); U = u(11:22,11:22,1); V = v(11:22,11:22,1);
Create a quiver plot of the subset you selected. The vectors
X
andY
represent the location of the base of each arrow, andU
andV
represent the directional components of each arrow. By default, thequiver
function shortens the arrows so they do not overlap. Callaxis equal
to use equal data unit lengths along each axis. This makes the arrows point in the correct direction.
quiver(X,Y,U,V) axis equal fig2plotly()
By default, the
quiver
function shortens arrows so they do not overlap. Disable automatic scaling so that arrow lengths are determined entirely byU
andV
by setting thescale
argument to0
.For instance, create a grid of
X
andY
values using themeshgrid
function. Specify the directional components using these values. Then, create a quiver plot with no automatic scaling.
[X,Y] = meshgrid(0:6,0:6); U = 0.25*X; V = 0.5*Y; quiver(X,Y,U,V,0) fig2plotly()
Plot the gradient and contours of the function z=xe-x2-y2. Use the
quiver
function to plot the gradient and thecontour
function to plot the contours.First, create a grid of x- and y-values that are equally spaced. Use them to calculate z. Then, find the gradient of z by specifying the spacing between points.
spacing = 0.2; [X,Y] = meshgrid(-2:spacing:2); Z = X.*exp(-X.^2 - Y.^2); [DX,DY] = gradient(Z,spacing); fig2plotly()
Display the gradient vectors as a quiver plot. Then, display contour lines in the same axes. Adjust the display so that the gradient vectors appear perpendicular to the contour lines by calling
axis equal
.
quiver(X,Y,DX,DY) hold on contour(X,Y,Z) axis equal hold off fig2plotly()
Create a quiver plot and specify a color for the arrows.
[X,Y] = meshgrid(-pi:pi/8:pi,-pi:pi/8:pi); U = sin(Y); V = cos(X); quiver(X,Y,U,V,'r') fig2plotly()
Create a grid of
X
andY
values and two sets ofU
andV
directional components.
[X,Y] = meshgrid(0:pi/8:pi,-pi:pi/8:pi); U1 = sin(X); V1 = cos(Y); U2 = sin(Y); V2 = cos(X);
Create a tiled layout of plots with two axes,
ax1
andax2
. Add a quiver plot and title to each axes. (Before R2019b, use *subplot
instead oftiledlayout
*andnexttile
.)
tiledlayout(1,2) ax1 = nexttile; quiver(ax1,X,Y,U1,V1) axis equal title(ax1,'Left Plot') ax2 = nexttile; quiver(ax2,X,Y,U2,V2) axis equal title(ax2,'Right Plot') fig2plotly()
Create a quiver plot and return the quiver object. Then, remove the arrowheads and add dot markers at the base of each arrow.
[X,Y] = meshgrid(-pi:pi/8:pi,-pi:pi/8:pi); U = sin(Y); V = cos(X); q = quiver(X,Y,U,V); q.ShowArrowHead = 'off'; q.Marker = '.'; fig2plotly()