Main Content

compass

(Not recommended) Arrows emanating from origin

  • Circular grid with arrows emanating from the origin

compass is not recommended. Use compassplot instead. (since R2024b)

For more information on updating your code, see Version History.

Description

compass(U,V) plots arrows originating from the point (0, 0). Specify the direction of arrows using the Cartesian coordinates U and V, with U indicating the x-coordinates and V indicating the y-coordinates. The number of arrows matches the number of elements in U.

The compass function plots arrows on a circular grid with theta-axis and r-axis tick labels within an Axes object. Therefore, the coordinates you specify do not match the labels displayed on the plot.

example

compass(Z) plots arrows using the real and imaginary parts of the complex values specified by Z, with the real part indicating the x-coordinates and the imaginary part indicating the y-coordinates. This syntax is equivalent to compass(real(Z),imag(Z)).

compass(___,LineSpec) sets the line style, marker symbol, and color for the arrows.

compass(ax,___) plots arrows in the specified axes instead of the current axes.

c = compass(___) returns a vector of Line objects. This syntax is useful for controlling the appearance of arrows.

example

Examples

collapse all

Create a compass plot by specifying the Cartesian coordinates of each arrow.

u = [5 3 -4 -3 5];
v = [1 5 3 -2 -6];
compass(u,v)

Compass plot containing five arrows

Specify the line width and color of a single arrow by assigning the arrow to a variable and then setting its properties. To do this, first create a compass plot and return an array of Line objects.

u = [3 5 -4 -3 5];
v = [5 1 3 -2 -6];
c = compass(u,v);

Assign the first arrow to the variable c1. The first arrow corresponds to the first elements of u and v. Then, change the line width and color.

c1 = c(1);
c1.LineWidth = 2;
c1.Color = "red";

Compass plot containing four thin blue arrows and one thick red arrow

Input Arguments

collapse all

x-coordinates, specified as a scalar, vector, or matrix. Specify Cartesian values. To convert data from polar to Cartesian, use pol2cart.

The size of U must match the size of V.

y-coordinates, specified as a scalar, vector, or matrix. Specify Cartesian values. To convert data from polar to Cartesian, use pol2cart.

The size of V must match the size of U.

Complex values, specified as a scalar, vector, or matrix. The real part of Z indicates the x-coordinates of arrows, and the imaginary part indicates the y-coordinates.

Line style, marker, and color, specified as a string scalar or character vector containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.

Example: "--or" is a red dashed line with circle markers.

Line StyleDescriptionResulting Line
"-"Solid line

Sample of solid line

"--"Dashed line

Sample of dashed line

":"Dotted line

Sample of dotted line

"-."Dash-dotted line

Sample of dash-dotted line, with alternating dashes and dots

MarkerDescriptionResulting Marker
"o"Circle

Sample of circle marker

"+"Plus sign

Sample of plus sign marker

"*"Asterisk

Sample of asterisk marker

"."Point

Sample of point marker

"x"Cross

Sample of cross marker

"_"Horizontal line

Sample of horizontal line marker

"|"Vertical line

Sample of vertical line marker

"square"Square

Sample of square marker

"diamond"Diamond

Sample of diamond marker

"^"Upward-pointing triangle

Sample of upward-pointing triangle marker

"v"Downward-pointing triangle

Sample of downward-pointing triangle marker

">"Right-pointing triangle

Sample of right-pointing triangle marker

"<"Left-pointing triangle

Sample of left-pointing triangle marker

"pentagram"Pentagram

Sample of pentagram marker

"hexagram"Hexagram

Sample of hexagram marker

Color NameShort NameRGB TripletAppearance
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

Target axes, specified as an Axes object.

Extended Capabilities

Version History

Introduced before R2006a

collapse all

R2024b: Not recommended

compass is not recommended. Use the compassplot function instead. The compassplot function uses a PolarAxes object, which provides more options for customization. For example, you can set PolarAxes properties to display either degree or radian theta units, adjust theta- and r-axis limits, or adjust aspects of the tick labels. However, there are no plans to remove the compass function.

Like other polar plotting functions, compassplot accepts polar coordinates instead of Cartesian coordinates. Use the cart2pol function to convert your data. This table shows some typical usages and how to update your code to use compassplot.

ScenarioNot RecommendedRecommended

Plot vectors of coordinates — Convert the Cartesian values of u and v to polar coordinates before passing them to compassplot.

compass(u,v) 

[theta,rho] = cart2pol(u,v);
compassplot(theta,rho)

Plot matrices of coordinates — The compass function plots all of the arrows using the same color. compassplot uses a different color for each matrix column. To make all the arrows the same color, set the SeriesIndex name-value argument to 1.

compass(u,v)

[theta,rho] = cart2pol(u,v);
compassplot(theta,rho,SeriesIndex=1)

Plot complex values

compass(Z)

compassplot(Z)

Specify line style and color

compass(u,v,"--r")

[theta,rho] = cart2pol(u,v);
compassplot(theta,rho,LineStyle="--",Color="r")