mplsoccer.quiver module

mplsoccer.quiver is a python module containing a function to plot arrows in Matplotlib and a complementary handler for adding the arrows to the legend.

mplsoccer.quiver.arrows(xstart, ystart, xend, yend, *args, ax=None, vertical=False, **kwargs)[source]

Utility wrapper around matplotlib.axes.Axes.quiver. Quiver uses locations and direction vectors usually. Here these are instead calculated automatically from the start and endpoints of the arrow. The function also automatically flips the x and y coordinates if the pitch is vertical.

Plot a 2D field of arrows. See:

  • xstart, ystart, xend, yend (array-like or scalar.) – Commonly, these parameters are 1D arrays. These should be the start and end coordinates of the lines.

  • C (1D 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.

  • ax (matplotlib.axes.Axes, default None) – The axis to plot on.

  • vertical (bool, default False) – If the orientation is vertical (True), then the code switches the x and y coordinates.

  • width (float, default 4) – Arrow shaft width in points.

  • headwidth (float, default 3) – Head width as a multiple of the arrow shaft width.

  • headlength (float, default 5) – Head length as a multiple of the arrow shaft width.

  • headaxislength (float, default: 4.5) – Head length at the shaft intersection. If this is equal to the headlength then the arrow will be a triangular shape. If greater than the headlength then the arrow will be wedge shaped. If less than the headlength the arrow will be swept back.

  • color (color or color sequence, optional) – Explicit color(s) for the arrows. If C has been set, color has no effect.

  • linewidth or linewidths or lw (float or sequence of floats) – Edgewidth of arrow.

  • edgecolor or ec or edgecolors (color or sequence of colors or ‘face’)

  • alpha (float or None) – Transparency of arrows.

  • **kwargs (All other keyword arguments are passed on to matplotlib.axes.Axes.quiver.)



Return type:



>>> from mplsoccer import Pitch
>>> pitch = Pitch()
>>> fig, ax = pitch.draw()
>>> pitch.arrows(20, 20, 45, 80, ax=ax)
>>> from mplsoccer.quiver import arrows
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> arrows([0.1, 0.4], [0.1, 0.5], [0.9, 0.4], [0.8, 0.8], ax=ax)
>>> ax.set_xlim(0, 1)
>>> ax.set_ylim(0, 1)