Soccer
from sportypy.surfaces.soccer import SoccerPitch
SoccerPitch
A subclass of BaseSurfacePlot to make a generic soccer pitch.
This allows for the creation of the soccer pitch in a way that is entirely parameterized by the pitch's baseline characteristics.
All attributes should default to 0.0 (if of a numeric type) or an empty string (if of a string type). Customized parameters may be specified via a child class (see below) or by directly specifying all necessary attributes of a valid soccer pitch. The attributes needed to instantiate a particular league's surface must be specified in the pitch_params dictionary. For many leagues, these will be provided in the surface_dimensions.json file in the data/ subdirectory of sportypy.
See the BaseSurfacePlot and BaseSurface class definitions for full details.
Attributes
-
league_code(str): The league for which the plot should be drawn. This is case-insensitive but should be the shortened name of the league (e.g. "Major League Soccer" should be either "MLS" or "mls"). The default is an empty string -
rotation(float): The angle (in degrees) through which to rotate the final plot. The default is0.0 -
x_trans(float): The amount that thexcoordinates are to be shifted. By convention, the +xaxis extends from the center of the surface towards the right-hand goal when viewing the pitch in TV view. The default is0.0 -
y_trans(float): The amount that theycoordinates are to be shifted. By convention, the +yaxis extends from the center of the surface towards the top of the pitch when viewing the pitch in TV view. The default is0.0 -
pitch_updates(dict): A dictionary of updated parameters to use for the soccer pitch. The default is an empty dictionary -
color_updates(dict): A dictionary of coloring parameters to pass to the plot. Defaults are provided in the class per each rule book, but this allows the plot to be more heavily customized/styled. The default is an empty dictionary -
units(str): The units that the final plot should utilize. The default units are the units specified in the rule book of the league. The default is"default" -
pitch_params(dict): A dictionary containing the following parameters of the pitch:pitch_length(float): The length of the pitch in TV viewpitch_width(float): The width of the pitch in TV viewline_thickness(float): The thickness of the lines on the pitch. All lines should have the same thicknesscenter_circle_radius(float): The (outer) radius of the center circle on the pitchcenter_mark_radius(float): The radius of the mark at the center at the pitchcorner_arc_radius(float): The (outer) radius of the arcs in the corners of the pitchgoal_line_defensive_mark_visible(boolean): Whether or not the defensive marks beyond the goal line should be visible in the resulting plottouchline_defensive_mark_visible(boolean): Whether or not the defensive marks beyond the touchline should be visible in the resulting plotdefensive_mark_depth(float): The depth (in any direction) of the defensive marks beyond the goal line or touchlinedefensive_mark_distance(float): The distance from the interior edge of the goal post to the defensive mark beyond the goal line. This will also be used to determine the distance from the goal line to the defensive mark beyond the touchlinedefensive_mark_separation_from_line(float): The distance from the exterior edge of the goal line to the interior edge of the defensive markpenalty_box_length(float): The length of the penalty box in TV view. This is the larger of the two boxes, and is usually 16.5 m (18 yards) from the back edge of the goal linepenalty_circle_radius(float): The radius of the arc at the top of the penalty box. This is measured from the center of the penalty markpenalty_mark_dist(float): The distance from the back edge of the goal line to the center of the penalty markinterior_of_goal_post_to_penalty_box(float): The distance from the interior edge of the goal post to the nearest edge of the penalty boxinterior_of_goal_post_to_goal_box(float): The distance from the interior edge of the goal post to the nearest edge of the goal boxgoal_box_length(float): The length of the goal box in TV view. This is the smaller of the two boxes, and is usually 5.5 m (6 yards) from the back edge of the goal linepenalty_mark_radius(float): The radius of the penalty markgoal_width(float): The interior distance between the goal postsgoal_depth(float): The depth of the goal from the back edge of the goal line
Leagues
Each class below is a SoccerPitch with that league's rule-book dimensions.
| Class | league_code | Description |
|---|---|---|
EPLPitch | epl | A subclass of SoccerPitch specific to the English Premier League. |
FIFAPitch | fifa | A subclass of SoccerPitch specific to FIFA. |
MLSPitch | mls | A subclass of SoccerPitch specific to FIFA. |
NCAAPitch | ncaa | A subclass of SoccerPitch specific to FIFA. |
NWSLPitch | nwsl | A subclass of SoccerPitch specific to FIFA. |
Methods
draw
SoccerPitch.draw(ax = None, display_range = 'full', xlim = None, ylim = None, rotation = None)
Draw the pitch.
Parameters
-
ax(matplotlib.Axes): An axes object onto which the plot can be drawn. IfNoneis supplied, then the currently-active Axes object will be used -
display_range(str): The portion of the surface to display. The entire surface will always be drawn under the hood, however this parameter limits what is shown in the final plot. The following explain what each display range corresponds to:"full": The entire pitch"in bounds only": The full in-bounds area of the pitch"in_bounds_only": The full in-bounds area of the pitch"offense": The offensive half of the pitch. This is the TV-right half"offence": The offensive half of the pitch. This is the TV-right half"offensivehalfpitch": The offensive half of the pitch. This is the TV-right half"offensive_half_pitch": The offensive half of the pitch. This is the TV-right half"offensive half pitch": The offensive half of the pitch. This is the TV-right half"defense": The defensive half of the pitch. This is the TV-left half"defence": The defensive half of the pitch. This is the TV-left half"defensivehalfpitch": The defensive half of the pitch. This is the TV-left half"defensive_half_pitch": The defensive half of the pitch. This is the TV-left half"defensive half pitch": The defensive half of the pitch. This is the TV-left half
The default is
"full" -
xlim(float or tuple of floats or None): The display range in thexdirection to be used. If a single float is provided, this will be used as the lower bound of thexcoordinates to display and the upper bound will be the +xend of the pitch. If a tuple, the two values will be used to determine the bounds. IfNone, then thedisplay_rangewill be used instead to set the bounds. The default isNone -
ylim(float or tuple of floats or None): The display range in theydirection to be used. If a single float is provided, this will be used as the lower bound of theycoordinates to display and the upper bound will be the +yupper touchline. If a tuple, the two values will be used to determine the bounds. IfNone, then the display_rangewillbe used instead to set the bounds. The default isNone -
rotation(float or None): Angle (in degrees) through which to rotate the pitch when drawing. If used, this will set the class attribute of_rotation. A value of0.0will correspond to a TV view of the pitch, where +xis to the right and +yis on top. The rotation occurs counter clockwise. The default isNone
cani_plot_leagues
SoccerPitch.cani_plot_leagues(league_code = None)
Show if a league can be plotted, or what leagues are pre-defined.
A user may wish to know if a specific curling league can be plotted. This method allows a user to check if that specific league code comes shipped with sportypy for easier plotting (if they provide the league code), or can also show what leagues are available to be plotted
Parameters
league_code(str or None): A league code that may or may not be shipped with the package. If the league code isNone, this will display all leagues that do come shipped withsportypy. The default isNone
Returns
Nothing, but a message will be printed out:
cani_color_features
SoccerPitch.cani_color_features()
Determine what features of the pitch can be colored.
This function is a helper function for the user to aid in plot styling and customization. The printed result of this method will be the names of the features that are able to be colored
Returns
Nothing, but a message will be printed out:
cani_change_dimensions
SoccerPitch.cani_change_dimensions()
Determine what features of the pitch can be re-parameterized.
This function is a helper function for the user to aid in customizing a pitch's parameters. The printed result of this method will be the names of the features that are able to be reparameterized. This method is also useful when defining new features and using an existing league's pitch dimensions as a starting point
Returns
Nothing, but a message will be printed out:
update_colors
SoccerPitch.update_colors(color_updates = {}, *args, **kwargs)
Update the colors currently used in the plot.
The colors can be passed at the initial instantiation of the class via the color_updates parameter, but this method allows the colors to be updated after the initial instantiation and will re-instantiate the class with the new colors
Parameters
color_updates(dict): A dictionary where the keys correspond to the name of the feature that's color is to be updated (seecani_color_features()method for a list of these names). The default is an empty dictionary
Returns
Nothing, but the class is re-instantiated with the updated colors:
update_pitch_params
SoccerPitch.update_pitch_params(pitch_param_updates = {}, *args, **kwargs)
Update the pitch's defining parameters.
This method should primarily be used in cases when plotting a league not currently supported by sportypy
Parameters
pitch_updates(dict): A dictionary where the keys correspond to the name of the parameter of the pitch that is to be updated (seecani_change_dimensions()method for a list of these parameters). The default is an empty dictionary
Returns
Nothing, but the class is re-instantiated with the updated parameters:
reset_colors
SoccerPitch.reset_colors()
Reset the features of the pitch to their default color set.
The colors can be passed at the initial instantiation of the class via the color_updates parameter, and through the update_colors() method, these can be changed. This method allows the colors to be reset to their default values after experiencing such a change
reset_pitch_params
SoccerPitch.reset_pitch_params()
Reset the features of the pitch to their default parameterizations.
The pitch parameters can be passed at the initial instantiation of the class via the pitch_updates parameter, and through the update_pitch_params() method, these can be changed. This method allows the feature parameterization to be reset to their default values after experiencing such a change