mplsoccer.linecollection module

A module with functions for using LineCollection to create lines.´´.

mplsoccer.linecollection.lines(xstart, ystart, xend, yend, color=None, n_segments=100, comet=False, transparent=False, alpha_start=0.01, alpha_end=1, cmap=None, ax=None, vertical=False, reverse_cmap=False, **kwargs)[source]

Plots lines using matplotlib.collections.LineCollection. This is a fast way to plot multiple lines without loops. Also enables lines that increase in width or opacity by splitting the line into n_segments of increasing width or opacity as the line progresses.

Parameters:
  • 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.

  • color (A matplotlib color or sequence of colors, defaults to None.) – Defaults to None. In that case the marker color is determined by the value rcParams[‘lines.color’]

  • n_segments (int, default 100) – If comet=True or transparent=True this is used to split the line into n_segments of increasing width/opacity.

  • comet (bool default False) – Whether to plot the lines increasing in width.

  • transparent (bool, default False) – Whether to plot the lines increasing in opacity.

  • linewidth or lw (array-like or scalar, default 5.) – Multiple linewidths not supported for the comet or transparent lines.

  • alpha_start (float, default 0.01) – The starting alpha value for transparent lines, between 0 (transparent) and 1 (opaque). If transparent = True the line will be drawn to linearly increase in opacity between alpha_start and alpha_end.

  • alpha_end (float, default 1) – The ending alpha value for transparent lines, between 0 (transparent) and 1 (opaque). If transparent = True the line will be drawn to linearly increase in opacity between alpha_start and alpha_end.

  • cmap (str, default None) – A matplotlib cmap (colormap) name

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

  • reverse_cmap (bool, default False) – Whether to reverse the cmap colors. If the pitch is horizontal and the y-axis is inverted then set this to True.

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

  • **kwargs (All other keyword arguments are passed on to matplotlib.collections.LineCollection.)

Returns:

LineCollection

Return type:

matplotlib.collections.LineCollection

Examples

>>> from mplsoccer import Pitch
>>> pitch = Pitch()
>>> fig, ax = pitch.draw()
>>> pitch.lines(20, 20, 45, 80, comet=True, transparent=True, ax=ax)
>>> from mplsoccer.linecollection import lines
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> lines([0.1, 0.4], [0.1, 0.5], [0.9, 0.4], [0.8, 0.8], ax=ax)