Plot a 2D field of arrows.
Call signature:
quiver([X, Y], U, V, [C], **kwargs)
X, Y define the arrow locations, U, V define the arrow directions, and C optionally sets the color.
Arrow length
The default settings auto-scales the length of the arrows to a reasonable size. To change this behavior see the scale and scale_units parameters.
Arrow shape
The arrow shape is determined by width, headwidth, headlength and headaxislength. See the notes below.
Arrow styling
Each arrow is internally represented by a filled polygon with a default edge linewidth of 0. As a result, an arrow is rather a filled area, not a line with a head, and PolyCollection properties like linewidth, edgecolor, facecolor, etc. act accordingly.
The x and y coordinates of the arrow locations.
If not given, they will be generated as a uniform integer meshgrid based on the dimensions of U and V.
If X and Y are 1D but U, V are 2D, X, Y are expanded to 2D using X, Y = np.meshgrid(X, Y). In this case len(X) and len(Y) must match the column and row dimensions of U and V.
The x and y direction components of the arrow vectors. The interpretation of these components (in data or in screen space) depends on angles.
U and V must have the same number of elements, matching the number of arrow locations in X, Y. U and V may be masked. Locations masked in any of U, V, and C will not be drawn.
Numeric data that defines the arrow colors by colormapping via norm and cmap.
This does not support explicit colors. If you want to set colors directly, use color instead. The size of C must match the number of arrow locations.
Method for determining the angle of the arrows.
'uv': Arrow direction in screen coordinates. Use this if the arrows symbolize a quantity that is not based on X, Y data coordinates.
If U == V the orientation of the arrow on the plot is 45 degrees counter-clockwise from the horizontal axis (positive to the right).
Arbitrary angles may be specified explicitly as an array of values in degrees, counter-clockwise from the horizontal axis.
In this case U, V is only used to determine the length of the arrows.
Note: inverting a data axis will correspondingly invert the arrows only with angles='xy'.
The part of the arrow that is anchored to the X, Y grid. The arrow rotates about this point.
'mid' is a synonym for 'middle'.
Scales the length of the arrow inversely.
Number of data units per arrow length unit, e.g., m/s per plot width; a smaller scale parameter makes the arrow longer. Default is None.
If None, a simple autoscaling algorithm is used, based on the average vector length and the number of vectors. The arrow length unit is given by the scale_units parameter.
If the scale kwarg is None, the arrow length unit. Default is None.
e.g. scale_units is 'inches', scale is 2.0, and (u, v) = (1, 0), then the vector will be 0.5 inches long.
If scale_units is 'width' or 'height', then the vector will be half the width/height of the axes.
If scale_units is 'x' then the vector will be 0.5 x-axis units. To plot vectors in the x-y plane, with u and v having the same units as x and y, use angles='xy', scale_units='xy', scale=1.
Affects the arrow size (except for the length). In particular, the shaft width is measured in multiples of this unit.
Supported values are:
The following table summarizes how these values affect the visible arrow size under zooming and figure size changes:
units | zoom | figure size change |
|---|---|---|
'x', 'y', 'xy' | arrow size scales | — |
'width', 'height' | — | arrow size scales |
'dots', 'inches' | — | — |
Shaft width in arrow units. All head parameters are relative to width.
The default depends on choice of units above, and number of vectors; a typical starting value is about 0.005 times the width of the plot.
Head width as multiple of shaft width. See the notes below.
Head length as multiple of shaft width. See the notes below.
Head length at shaft intersection as multiple of shaft width. See the notes below.
Length below which arrow scales, in units of head length. Do not set this to less than 1, or small arrows will look terrible!
Minimum length as a multiple of shaft width; if an arrow length is less than this, plot a dot (hexagon) of this diameter instead.
Explicit color(s) for the arrows. If C has been set, color has no effect.
This is a synonym for the PolyCollection facecolor parameter.
If given, all parameters also accept a string s, which is interpreted as data[s] (unless this raises an exception).
PolyCollection properties, optional
All other keyword arguments are passed on to PolyCollection:
Property | Description |
|---|---|
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image | |
array-like or scalar or None | |
bool | |
| bool or list of bools |
array-like or None | |
| |
(vmin: float, vmax: float) | |
| |
bool | |
Patch or (Path, Transform) or None | |
| |
color or list of RGBA tuples | |
| |
| |
str | |
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} | |
bool | |
| |
object | |
| str or tuple or list thereof |
| float or list of floats |
bool | |
| |
| |
(N, 2) or (2,) array-like | |
list of | |
list of array-like | |
None or bool or float or callable | |
float | |
bool | |
|
|
(scale: float, length: float, randomness: float) | |
bool or None | |
str | |
list of str or None | |
list of array-like | |
unknown | |
bool | |
float |
See also
Axes.quiverkeyAdd a key to a quiver plot.
Arrow shape
The arrow is drawn as a polygon using the nodes as shown below. The values headwidth, headlength, and headaxislength are in units of width.
The defaults give a slightly swept-back arrow. Here are some guidelines how to get other head shapes:
matplotlib.axes.Axes.quiver
© 2012–2023 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.quiver.html