matplotlib.pyplot.quiver — Matplotlib 3.10.3 documentation (original) (raw)

matplotlib.pyplot.quiver(*args, data=None, **kwargs)[source]#

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. The arguments X, Y, U, V, C are positional-only.

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.

Parameters:

X, Y1D or 2D array-like, optional

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.

U, V1D or 2D array-like

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.

C1D or 2D array-like, optional

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.

angles{'uv', 'xy'} or array-like, default: 'uv'

Method for determining the angle of the arrows.

Note: inverting a data axis will correspondingly invert the arrows only with angles='xy'.

pivot{'tail', 'mid', 'middle', 'tip'}, default: 'tail'

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

scalefloat, optional

Scales the length of the arrow inversely.

Number of data values represented by one unit of arrow length on the plot. For example, if the data represents velocity in meters per second (m/s), the scale parameter determines how many meters per second correspond to one unit of arrow length relative to the width of the plot. Smaller scale parameter makes the arrow longer.

By default, an autoscaling algorithm is used to scale the arrow length to a reasonable size, which is based on the average vector length and the number of vectors.

The arrow length unit is given by the scale_units parameter.

scale_units{'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'

The physical image unit, which is used for rendering the scaled arrow data U, V.

The rendered arrow length is given by

length in x direction = fracumathrmscalemathrmscaleunitfrac{u}{mathrm{scale}} mathrm{scale_unit}fracumathrmscalemathrmscaleunit

length in y direction = fracvmathrmscalemathrmscaleunitfrac{v}{mathrm{scale}} mathrm{scale_unit}fracvmathrmscalemathrmscaleunit

For example, (u, v) = (0.5, 0) with scale=10, scale_unit="width" results in a horizontal arrow with a length of 0.5 / 10 * "width", i.e. 0.05 times the Axes width.

Supported values are:

Note: Setting scale_units without setting scale does not have any effect because the scale units only differ by a constant factor and that is rescaled through autoscaling.

units{'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'

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:

widthfloat, optional

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.

headwidthfloat, default: 3

Head width as multiple of shaft width. See the notes below.

headlengthfloat, default: 5

Head length as multiple of shaft width. See the notes below.

headaxislengthfloat, default: 4.5

Head length at shaft intersection as multiple of shaft width. See the notes below.

minshaftfloat, default: 1

Length below which arrow scales, in units of head length. Do not set this to less than 1, or small arrows will look terrible!

minlengthfloat, default: 1

Minimum length as a multiple of shaft width; if an arrow length is less than this, plot a dot (hexagon) of this diameter instead.

colorcolor or list color, optional

Explicit color(s) for the arrows. If C has been set, color has no effect.

This is a synonym for the PolyCollection facecolor parameter.

Returns:

Quiver

Other Parameters:

dataindexable object, optional

If given, all parameters also accept a string s, which is interpreted as data[s] if s is a key in data.

**kwargsPolyCollection properties, optional

All other keyword arguments are passed on to PolyCollection:

Notes

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.

../../_images/quiver_sizes.svg

The defaults give a slightly swept-back arrow. Here are some guidelines how to get other head shapes:

Examples using matplotlib.pyplot.quiver#