floodlight.core.pitch
- class floodlight.core.pitch.Pitch(xlim, ylim, unit, boundaries, length=None, width=None, sport=None)[source]
Pitch and coordinate system specifications. Core class of floodlight.
- Parameters
xlim (Tuple[Numeric, Numeric]) – Limits of pitch boundaries in longitudinal direction. This tuple has the form (x_min, x_max) and delimits the length of the pitch (not of any actual data) within the coordinate system.
ylim (Tuple[Numeric, Numeric]) – Limits of pitch boundaries in lateral direction. This tuple has the form (y_min, y_max) and delimits the width of the pitch (not of any actual data) within the coordinate system.
unit ({‘m’, ‘cm’, ‘percent’, ‘normed’}) – The unit in which data is measured along axes. The values ‘percent’ and ‘normed’ can be used to denote standardized pitches where data is scaled along the axes independent of the actual pitch size. In this case, ‘percent’ refers to a scaling onto the range (0, 100), and ‘normed’ to all other scalings. To get non-distored calculations from these unit-systems, the length and width attributes need to be specified.
boundaries (str) – One of {‘fixed’, ‘flexible’}. Here, ‘fixed’ denotes coordinate systems that limit axes to the respective xlim and ylim. On the contrary, ‘flexible’ coordinate systems do not explicitly specify a limit. Instead, the limit is implicitly set by the actual pitch length and width.
length (Numeric, optional) – Actual pitch length in m.
width (Numeric, optional) – Actual pitch width in m.
sport (str, optional) – Sport for which the pitch is used. This is used to automatically generate lines and markings.
- Variables
center (tuple) – Returns coordinates of the pitch center.
is_metrical (bool) – Returns True if the object’s unit is metrical, False otherwise.
- classmethod from_template(template_name, **kwargs)[source]
Creates a Pitch object representing common data provider formats.
- Parameters
template_name (str) – The name of the template the pitch should follow. Currently supported are {‘dfl’, ‘eigd’, ‘opta’, ‘statsbomb’, ‘secondspectrum’, ‘statsperform_event’, ‘statsperform_tracking’, ‘statsperform_open’, ‘tracab’}.
kwargs – You may pass optional arguments (length, width, sport) used for class instantiation. For some data providers, additional kwargs are needed to represent their format correctly. For example, pass the length and width argument to create a Pitch object in the ‘tracab’ format.
- Returns
pitch – A class instance of the given provider format.
- Return type
- plot(color_scheme='standard', show_axis_ticks=False, ax=None, **kwargs)[source]
Plots a pitch on a matplotlib.axes for a given sport.
- Parameters
color_scheme (str, optional) – Color scheme of the plot. One of {‘standard’, ‘bw’}. Defaults to ‘standard’.
show_axis_ticks (bool, optional) – If set to True, the axis ticks are visible. Defaults to False.
ax (matplotlib.axes, optional) – Axes from matplotlib library on which the playing field is plotted. If ax is None, a default-sized matplotlib.axes object is created.
kwargs – Optional keyworded arguments {‘linewidth’, ‘zorder’, ‘scalex’, ‘scaley’} which can be used for the plot functions from matplotlib. The kwargs are only passed to all the plot functions of matplotlib.
- Returns
axes – Axes from matplotlib library on which the specified pitch is plotted.
- Return type
matplotlib.axes
Notes
The kwargs are only passed to the plot functions of matplotlib. To customize the plots have a look at matplotlib. For example in order to modify the linewidth pass a float to the keyworded argument ‘linewidth’. The same principle applies to other kwargs like ‘zorder’, ‘scalex’ and ‘scaley’.
Examples