8000 improved documentation of quvier plot · matplotlib/matplotlib@cba81f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit cba81f9

Browse files
committed
improved documentation of quvier plot
1 parent 235bf97 commit cba81f9

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

lib/matplotlib/quiver.py

Lines changed: 60 additions & 18 deletions
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,60 @@
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+
If *None*, a autoscaling algorithm is used to scale the arrow lenght to a
132+
reasonable size, which is based on the average vector length and the number of
133+
vectors.If the autoscaling does not yield a reasonable result, the user has to
134+
manually define a scale.
135+
136+
The arrow length unit is given by the *scale_units* parameter.
137+
138+
scale_units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'
139+
140+
The physical image unit, which is used for rendering the scaled arrow data *U*, *V*.
141+
142+
The rendered arrow length is given by
143+
144+
length in x direction = $\frac{u}{\mathrm{scale}} \mathrm{scale_unit}$
145+
146+
length in y direction = $\frac{v}{\mathrm{scale}} \mathrm{scale_unit}$
147+
148+
For example, ``(u, v) = (0.5, 0)`` with ``scale=10, scale_unit="width"`` results
149+
in a horizontal arrow with a length of *0.5 / 10 * "width"*, i.e. 0.05 times the
150+
Axes width.
151+
152+
Supported values are:
153+
154+
- 'width' or 'height': The arrow length is scaled relative to the width or height
155+
of the Axes.
156+
For example, ``scale_units='width', scale=1.0``, will result in an arrow length
157+
of width of the Axes.
119158
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.
159+
- 'dots': The arrow len EDB5 gth of the arrows is in measured in display dots (pixels).
123160
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*.
161+
- 'inches': Arrow lengths are scaled based on the DPI (dots per inch) of the figure.
162+
This ensures that the arrows have a consistent physical size on the figure,
163+
in inches, regardless of data values or plot scaling.
164+
For example, if scale_units is 'inches', scale is 2.0, and `(u, v) = (1, 0)`,
165+
then the vector will be 0.5 inches long.
126166
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.
167+
- 'x' or 'y': The arrow length is scaled relative to the x or y axis units.
168+
For example, if *scale_units* is 'x' and *scale* is 1.0, the vector will be
169+
x-axis units long.
129170
130-
If *scale_units* is 'width' or 'height', then the vector will be half the
131-
width/height of the axes.
171+
- 'xy': Arrow length will be same as 'x' or 'y' units.
172+
This is useful for creating vectors in the x-y plane where u and v have
173+
the same units as x and y. To plot vectors in the x-y plane with u and v having
174+
the same units as x and y, use ``angles='xy', scale_units='xy', scale=1``.
132175
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``.
176+
Note: setting scale_units without setting scale does not have any effect because
177+
the scale units only differ by a constant factor and that is rescaled through
178+
autoscaling.
137179
138180
units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'
139181
Affects the arrow size (except for the length). In particular, the shaft

0 commit comments

Comments
 (0)
0