add_arrows(lines, n=3, size=12, style='->', dorestrict=False, positions=False)¶
Add directional arrows along a plotted line. Useful for plotting flow lines, magnetic field lines, or other directional traces.
For each line, arrows will be added using :method:`~matplotlib.axes.Axes.annotate`. Arrows will be spread evenly over the line using the number of points in the line as the metric for spacing. For example, if a line has 120 points and 3 arrows are requested, an arrow will be added at point number 30, 60, and 90. Arrow color and alpha is obtained from the parent line.
- Other Parameters
Number of arrows to add to each line; defaults to 3.
The size of the arrows in points. Defaults to 12.
If True (default), only points along the line within the current limits of the axes will be considered when distributing arrows.
- positionsNx2 array
N must be the number of lines provided via the argument lines. If provided, only one arrow will be placed per line. positions sets the explicit location of each arrow for each line as X-Y space in Axes coordinates.
The algorithm works by dividing the line in to n*+1 segments and placing an arrow between each segment, endpoints excluded. Arrows span the shortest distance possible, i.e., two adjacent points along a line. For lines that are long spatially but sparse in points, the arrows will have long tails that may extend beyond axes bounds. For explicit positions, the arrow is placed at the point on the curve closest to that position and the exact position is not always attainable. A maximum number of arrows equal to one-half of the number of points in a line per line will be created, so not all lines will receive *n arrows.
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> x = np.arange(1, 10, .01) >>> y = np.sin(x) >>> line = plt.plot(x,y) >>> add_arrows(line, n=15, style='-|>')