Quiver or vector plot - MATLAB quiver (2024)

Quiver or vector plot

collapse all in page

  • Quiver or vector plot - MATLAB quiver (1)

Syntax

quiver(X,Y,U,V)

quiver(U,V)

quiver(___,scale)

quiver(___,LineSpec)

quiver(___,LineSpec,'filled')

quiver(___,Name,Value)

quiver(ax,___)

q = quiver(___)

Description

example

quiver(X,Y,U,V) plots arrows with directional components U and V at the Cartesian coordinates specified by X and Y. For example, the first arrow originates from the point X(1) and Y(1), extends horizontally according to U(1), and extends vertically according to V(1). By default, the quiver function scales the arrow lengths so that they do not overlap.

quiver(U,V) plots arrows with directional components specified by U and V at equally spaced points.

  • If U and V are vectors, then the x-coordinates of the arrows range from 1 to the number of elements in U and V, and the y-coordinates are all 1.

  • If U and V are matrices, then the x-coordinates of the arrows range from 1 to the number of columns in U and V, and the y-coordinates of the arrows range from 1 to the number of rows in U and V.

example

quiver(___,scale) adjusts the length of arrows:

  • When scale is a positive number, the quiver function automatically adjusts the lengths of arrows so they do not overlap, then stretches them by a factor of scale. For example, a scale of 2 doubles the length of arrows, and a scale of 0.5 halves the length of arrows.

  • When scale is 'off' or 0, such as quiver(X,Y,U,V,'off'), then automatic scaling is disabled.

example

quiver(___,LineSpec) sets the line style, marker, and color. Markers appear at the points specified by X and Y. If you specify a marker using LineSpec, then quiver does not display arrowheads. To specify a marker and display arrowheads, set the Marker property instead.

quiver(___,LineSpec,'filled') fills the markers specified by LineSpec.

quiver(___,Name,Value) specifies quiver properties using one or more name-value pair arguments. For a list of properties, see Quiver Properties. Specify name-value pair arguments after all other input arguments. Name-value pair arguments apply to all of the arrows in the quiver plot.

example

quiver(ax,___) creates the quiver plot in the axes specified by ax instead of the current axes (gca). The argument ax can precede any of the input argument combinations in the previous syntaxes.

example

q = quiver(___) returns a Quiver object. This object is useful for controlling the properties of the quiver plot after creating it.

Examples

collapse all

Create Quiver Plot

Open Live Script

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 and Y represent the location of the tail of each arrow, and U and V represent the directional components of each arrow. By default, the quiver function shortens the arrows so they do not overlap. Call axis 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

Disable Automatic Scaling

Open Live Script

By default, the quiver function shortens arrows so they do not overlap. Disable automatic scaling so that arrow lengths are determined entirely by U and V by setting the scale argument to 0.

For instance, create a grid of X and Y values using the meshgrid 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)

Quiver or vector plot - MATLAB quiver (3)

Plot Gradient and Contours

Open Live Script

Plot the gradient and contours of the function z=xe-x2-y2. Use the quiver function to plot the gradient and the contour 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);

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 oncontour(X,Y,Z)axis equalhold off

Quiver or vector plot - MATLAB quiver (4)

Specify Arrow Color

Open Live Script

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')

Quiver or vector plot - MATLAB quiver (5)

Specify Axes for Quiver Plot

Open Live Script

Create a grid of X and Y values and two sets of U and V 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 and ax2. Add a quiver plot and title to each axes. (Before R2019b, use subplot instead of tiledlayout and nexttile.)

tiledlayout(1,2)ax1 = nexttile;quiver(ax1,X,Y,U1,V1)axis equaltitle(ax1,'Left Plot')ax2 = nexttile;quiver(ax2,X,Y,U2,V2)axis equaltitle(ax2,'Right Plot')

Quiver or vector plot - MATLAB quiver (6)

Modify Quiver Plot After Creation

Open Live Script

Create a quiver plot and return the quiver object. Then, remove the arrowheads and add dot markers to the end of each tail.

[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 = '.';

Quiver or vector plot - MATLAB quiver (7)

Input Arguments

collapse all

Xx-coordinates of arrow tails
scalar | vector | matrix

x-coordinates of the arrow tails, specified as a scalar, a vector, or a matrix.

If X and Y are vectors and U and V are matrices, then quiver expands X and Y into matrices. In this case, size(U) and size(V) must equal [length(Y) length(X)]. For more information about expanding vectors into matrices, see meshgrid.

If X and Y are matrices, then X, Y, U, and V must be the same size.

Yy-coordinates of arrow tails
scalar | vector | matrix

y-coordinates of the arrows tails, specified as a scalar, a vector, or a matrix.

If X and Y are vectors and U and V are matrices, then quiver expands X and Y into matrices. In this case, size(U) and size(V) must equal [length(Y) length(X)]. For more information about expanding vectors into matrices, see meshgrid.

If X and Y are matrices, then X, Y, U, and V must be the same size.

Ux-components
scalar | vector | matrix

x-components of arrows, specified as a scalar, vector, or matrix.

If X and Y are vectors, then size(U) and size(V) must equal [length(Y) length(X)].

If X and Y are matrices, then X, Y, U, and V must be the same size.

Vy-components
scalar | vector | matrix

y-components of arrows, specified as a scalar, vector, or matrix.

If X and Y are vectors, then size(U) and size(V) must equal [length(Y) length(X)].

If X and Y are matrices, then X, Y, U, and V must be the same size.

LineSpecLine style, marker, and color
character vector | string

Line style, marker, and color, specified as a character vector or string containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color).

If you specify a marker using LineSpec, then quiver does not display arrowheads. To specify a marker and display arrowheads, set the Marker property instead.

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

Line StyleDescriptionResulting Line
"-"Solid line

Quiver or vector plot - MATLAB quiver (8)

"--"Dashed line

Quiver or vector plot - MATLAB quiver (9)

":"Dotted line

Quiver or vector plot - MATLAB quiver (10)

"-."Dash-dotted line

Quiver or vector plot - MATLAB quiver (11)

MarkerDescriptionResulting Marker
"o"Circle

Quiver or vector plot - MATLAB quiver (12)

"+"Plus sign

Quiver or vector plot - MATLAB quiver (13)

"*"Asterisk

Quiver or vector plot - MATLAB quiver (14)

"."Point

Quiver or vector plot - MATLAB quiver (15)

"x"Cross

Quiver or vector plot - MATLAB quiver (16)

"_"Horizontal line

Quiver or vector plot - MATLAB quiver (17)

"|"Vertical line

Quiver or vector plot - MATLAB quiver (18)

"square"Square

Quiver or vector plot - MATLAB quiver (19)

"diamond"Diamond

Quiver or vector plot - MATLAB quiver (20)

"^"Upward-pointing triangle

Quiver or vector plot - MATLAB quiver (21)

"v"Downward-pointing triangle

Quiver or vector plot - MATLAB quiver (22)

">"Right-pointing triangle

Quiver or vector plot - MATLAB quiver (23)

"<"Left-pointing triangle

Quiver or vector plot - MATLAB quiver (24)

"pentagram"Pentagram

Quiver or vector plot - MATLAB quiver (25)

"hexagram"Hexagram

Quiver or vector plot - MATLAB quiver (26)

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

Quiver or vector plot - MATLAB quiver (27)

"green""g"[0 1 0]

Quiver or vector plot - MATLAB quiver (28)

"blue""b"[0 0 1]

Quiver or vector plot - MATLAB quiver (29)

"cyan" "c"[0 1 1]

Quiver or vector plot - MATLAB quiver (30)

"magenta""m"[1 0 1]

Quiver or vector plot - MATLAB quiver (31)

"yellow""y"[1 1 0]

Quiver or vector plot - MATLAB quiver (32)

"black""k"[0 0 0]

Quiver or vector plot - MATLAB quiver (33)

"white""w"[1 1 1]

Quiver or vector plot - MATLAB quiver (34)

scaleArrow scaling factor
nonnegative number | 'off'

Arrow scaling factor, specified as a nonnegative number or 'off'. By default, the quiver function automatically scales the arrows so they do not overlap. The quiver function applies the scaling factor after it automatically scales the arrows.

Specifying scale is the same as setting the AutoScaleFactor property of the quiver object. For example, specifying scale as 2 doubles the length of the arrows. Specifying scale as 0.5 halves the length of the arrows.

To disable automatic scaling, specify scale as 'off' or 0. When you specify either of these values, the AutoScale property of the quiver object is set to 'off' and the length of the arrow is determined entirely by U and V.

axTarget axes
Axes object

Target axes, specified as an Axes object. If you do not specify the axes, then the quiver function uses the current axes.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Color','r','LineWidth',1

Note

The properties listed here are only a subset. For a complete list, see Quiver Properties.

LineWidthWidth of arrow stem and head
0.5 (default) | scalar numeric value

Width of arrow stem and head, specified as a scalar numeric value greater than zero in point units. One point equals 1/72 inch. The default value is 0.5 point.

Example: 0.75

ShowArrowHeadArrowhead display
'on' (default) | on/off logical value

Arrowhead display, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Display the vectors with arrowheads.

  • 'off' — Display the vectors without arrowheads.

AutoScaleUse automatic scale factor
'on' (default) | on/off logical value

Use the automatic scale factor to adjust arrow length, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Use the AutoScaleFactor value as a secondary multiplier to scale the arrow lengths to fit within the grid-defined coordinate data and scale arrows so that they do not overlap.

  • 'off' — Do not scale the arrow lengths.

AutoScaleFactorAutomatic scale factor
0.9 (default) | scalar

Automatic scale factor, specified as a scalar. The automatic scale factor is a multiplier that adjusts the magnitudes of the arrows if the AutoScale property is "on". For example, a value of 2 doubles the length of the arrows, and a value of 0.5 halves the length of the arrows.

Note

  • This property has no effect if the AutoScale property is set to "off".

  • Adjusting the AutoScaleFactor property updates the ScaleFactor property.

Tips

To create a quiver plot using polar coordinates, first convert them to Cartesian coordinates using the pol2cart function.

Extended Capabilities

Version History

Introduced before R2006a

See Also

Functions

  • contour | quiver3 | meshgrid

Properties

  • Quiver Properties

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Quiver or vector plot - MATLAB quiver (35)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Quiver or vector plot - MATLAB quiver (2024)
Top Articles
Here Are The Recipes We Loved Recently (And Would 100% Make Again)
Holiday Quiche Recipe — Caralyn Mirand Koch
Lengua With A Tilde Crossword
Average Jonas Wife
Gamevault Agent
Windcrest Little League Baseball
The Daily News Leader from Staunton, Virginia
10 Popular Hair Growth Products Made With Dermatologist-Approved Ingredients to Shop at Amazon
The Realcaca Girl Leaked
Sissy Transformation Guide | Venus Sissy Training
5 Bijwerkingen van zwemmen in een zwembad met te veel chloor - Bereik uw gezondheidsdoelen met praktische hulpmiddelen voor eten en fitness, deskundige bronnen en een betrokken gemeenschap.
Ub Civil Engineering Flowsheet
Wfin Local News
Draconic Treatise On Mining
Tribune Seymour
2013 Chevy Cruze Coolant Hose Diagram
10 Great Things You Might Know Troy McClure From | Topless Robot
Https://Gw.mybeacon.its.state.nc.us/App
Blue Beetle Showtimes Near Regal Swamp Fox
People Portal Loma Linda
Gmail Psu
Rhinotimes
Craigslist Free Stuff Greensboro Nc
Abortion Bans Have Delayed Emergency Medical Care. In Georgia, Experts Say This Mother’s Death Was Preventable.
White Pages Corpus Christi
ZURU - XSHOT - Insanity Mad Mega Barrel - Speelgoedblaster - Met 72 pijltjes | bol
Puss In Boots: The Last Wish Showtimes Near Cinépolis Vista
Violent Night Showtimes Near Century 14 Vallejo
Menus - Sea Level Oyster Bar - NBPT
New Stores Coming To Canton Ohio 2022
Lacey Costco Gas Price
Evil Dead Rise - Everything You Need To Know
Jt Closeout World Rushville Indiana
Wisconsin Volleyball Team Leaked Uncovered
Rlcraft Toolbelt
Eaccess Kankakee
EST to IST Converter - Time Zone Tool
One Credit Songs On Touchtunes 2022
Black Adam Showtimes Near Amc Deptford 8
Final Exam Schedule Liberty University
Magicseaweed Capitola
Directions To Advance Auto
Mid America Clinical Labs Appointments
Guided Practice Activities 5B-1 Answers
Patricia And Aaron Toro
'The Nun II' Ending Explained: Does the Immortal Valak Die This Time?
The Machine 2023 Showtimes Near Roxy Lebanon
Oefenpakket & Hoorcolleges Diagnostiek | WorldSupporter
SF bay area cars & trucks "chevrolet 50" - craigslist
Wieting Funeral Home '' Obituaries
Escape From Tarkov Supply Plans Therapist Quest Guide
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 5841

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.