Skip to content

Commit 64d984a

Browse files
authored
Improved documentation for quiver (matplotlib#28863)
1 parent 835d512 commit 64d984a

File tree

2 files changed

+62
-21
lines changed

2 files changed

+62
-21
lines changed

doc/missing-references.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes._axes.Axes.fill_betweenx:121",
309309
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes._axes.Axes.hexbin:217",
310310
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes._axes.Axes.pcolor:186",
311-
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes._axes.Axes.quiver:215",
311+
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes._axes.Axes.quiver:255",
312312
"lib/matplotlib/collections.py:docstring of matplotlib.artist.AsteriskPolygonCollection.set:44",
313313
"lib/matplotlib/collections.py:docstring of matplotlib.artist.CircleCollection.set:44",
314314
"lib/matplotlib/collections.py:docstring of matplotlib.artist.PathCollection.set:44",
@@ -323,11 +323,11 @@
323323
"lib/matplotlib/pyplot.py:docstring of matplotlib.pyplot.fill_betweenx:121",
324324
"lib/matplotlib/pyplot.py:docstring of matplotlib.pyplot.hexbin:217",
325325
"lib/matplotlib/pyplot.py:docstring of matplotlib.pyplot.pcolor:186",
326-
"lib/matplotlib/pyplot.py:docstring of matplotlib.pyplot.quiver:215",
326+
"lib/matplotlib/pyplot.py:docstring of matplotlib.pyplot.quiver:255",
327327
"lib/matplotlib/quiver.py:docstring of matplotlib.artist.Barbs.set:45",
328328
"lib/matplotlib/quiver.py:docstring of matplotlib.artist.Quiver.set:45",
329329
"lib/matplotlib/quiver.py:docstring of matplotlib.quiver.Barbs:212",
330-
"lib/matplotlib/quiver.py:docstring of matplotlib.quiver.Quiver:251",
330+
"lib/matplotlib/quiver.py:docstring of matplotlib.quiver.Quiver:291",
331331
"lib/mpl_toolkits/mplot3d/art3d.py:docstring of matplotlib.artist.Path3DCollection.set:46",
332332
"lib/mpl_toolkits/mplot3d/art3d.py:docstring of matplotlib.artist.Poly3DCollection.set:45"
333333
],

lib/matplotlib/quiver.py

+59-18
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,29 @@
8787
angles : {'uv', 'xy'} or array-like, default: 'uv'
8888
Method for determining the angle of the arrows.
8989
90-
- 'uv': Arrow direction in screen coordinates. Use this if the arrows
91-
symbolize a quantity that is not based on *X*, *Y* data coordinates.
90+
- 'uv': Arrow directions are based on
91+
:ref:`display coordinates <coordinate-systems>`; i.e. a 45° angle will
92+
always show up as diagonal on the screen, irrespective of figure or Axes
93+
aspect ratio or Axes data ranges. This is useful when the arrows represent
94+
a quantity whose direction is not tied to the x and y data coordinates.
9295
9396
If *U* == *V* the orientation of the arrow on the plot is 45 degrees
9497
counter-clockwise from the horizontal axis (positive to the right).
9598
9699
- 'xy': Arrow direction in data coordinates, i.e. the arrows point from
97-
(x, y) to (x+u, y+v). Use this e.g. for plotting a gradient field.
100+
(x, y) to (x+u, y+v). This is ideal for vector fields or gradient plots
101+
where the arrows should directly represent movements or gradients in the
102+
x and y directions.
98103
99104
- Arbitrary angles may be specified explicitly as an array of values
100105
in degrees, counter-clockwise from the horizontal axis.
101106
102107
In this case *U*, *V* is only used to determine the length of the
103108
arrows.
104109
110+
For example, ``angles=[30, 60, 90]`` will orient the arrows at 30, 60, and 90
111+
degrees respectively, regardless of the *U* and *V* components.
112+
105113
Note: inverting a data axis will correspondingly invert the
106114
arrows only with ``angles='xy'``.
107115
@@ -114,26 +122,59 @@
114122
scale : float, optional
115123
Scales the length of the arrow inversely.
116124
117-
Number of data units per arrow length unit, e.g., m/s per plot width; a
118-
smaller scale parameter makes the arrow longer. Default is *None*.
125+
Number of data values represented by one unit of arrow length on the plot.
126+
For example, if the data represents velocity in meters per second (m/s), the
127+
scale parameter determines how many meters per second correspond to one unit of
128+
arrow length relative to the width of the plot.
129+
Smaller scale parameter makes the arrow longer.
130+
131+
By default, an autoscaling algorithm is used to scale the arrow length to a
132+
reasonable size, which is based on the average vector length and the number of
133+
vectors.
134+
135+
The arrow length unit is given by the *scale_units* parameter.
136+
137+
scale_units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'
138+
139+
The physical image unit, which is used for rendering the scaled arrow data *U*, *V*.
140+
141+
The rendered arrow length is given by
142+
143+
length in x direction = $\\frac{u}{\\mathrm{scale}} \\mathrm{scale_unit}$
144+
145+
length in y direction = $\\frac{v}{\\mathrm{scale}} \\mathrm{scale_unit}$
146+
147+
For example, ``(u, v) = (0.5, 0)`` with ``scale=10, scale_unit="width"`` results
148+
in a horizontal arrow with a length of *0.5 / 10 * "width"*, i.e. 0.05 times the
149+
Axes width.
150+
151+
Supported values are:
152+
153+
- 'width' or 'height': The arrow length is scaled relative to the width or height
154+
of the Axes.
155+
For example, ``scale_units='width', scale=1.0``, will result in an arrow length
156+
of width of the Axes.
119157
120-
If *None*, a simple autoscaling algorithm is used, based on the average
121-
vector length and the number of vectors. The arrow length unit is given by
122-
the *scale_units* parameter.
158+
- 'dots': The arrow length of the arrows is in measured in display dots (pixels).
123159
124-
scale_units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, optional
125-
If the *scale* kwarg is *None*, the arrow length unit. Default is *None*.
160+
- 'inches': Arrow lengths are scaled based on the DPI (dots per inch) of the figure.
161+
This ensures that the arrows have a consistent physical size on the figure,
162+
in inches, regardless of data values or plot scaling.
163+
For example, ``(u, v) = (1, 0)`` with ``scale_units='inches', scale=2`` results
164+
in a 0.5 inch-long arrow.
126165
127-
e.g. *scale_units* is 'inches', *scale* is 2.0, and ``(u, v) = (1, 0)``,
128-
then the vector will be 0.5 inches long.
166+
- 'x' or 'y': The arrow length is scaled relative to the x or y axis units.
167+
For example, ``(u, v) = (0, 1)`` with ``scale_units='x', scale=1`` results
168+
in a vertical arrow with the length of 1 x-axis unit.
129169
130-
If *scale_units* is 'width' or 'height', then the vector will be half the
131-
width/height of the axes.
170+
- 'xy': Arrow length will be same as 'x' or 'y' units.
171+
This is useful for creating vectors in the x-y plane where u and v have
172+
the same units as x and y. To plot vectors in the x-y plane with u and v having
173+
the same units as x and y, use ``angles='xy', scale_units='xy', scale=1``.
132174
133-
If *scale_units* is 'x' then the vector will be 0.5 x-axis
134-
units. To plot vectors in the x-y plane, with u and v having
135-
the same units as x and y, use
136-
``angles='xy', scale_units='xy', scale=1``.
175+
Note: Setting *scale_units* without setting scale does not have any effect because
176+
the scale units only differ by a constant factor and that is rescaled through
177+
autoscaling.
137178
138179
units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'
139180
Affects the arrow size (except for the length). In particular, the shaft

0 commit comments

Comments
 (0)