Skip to main content

Hockey

from sportypy.surfaces.hockey import HockeyRink

HockeyRink​

A subclass of BaseSurfacePlot to make a generic hockey rink.

This allows for the creation of the hockey rink in a way that is entirely parameterized by the rink'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 hockey rink. The attributes needed to instantiate a particular league's surface must be specified in the rink_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. "National Hockey League" should be either "NHL" or "nhl"). The default is an empty string

  • rotation (float): The angle (in degrees) through which to rotate the final plot. The default is 0.0

  • x_trans (float): The amount that the x coordinates are to be shifted. By convention, the +x axis extends from the center of the surface towards the right-hand goal when viewing the rink in TV view. The default is 0.0

  • y_trans (float): The amount that the y coordinates are to be shifted. By convention, the +y axis extends from the center of the surface towards the top of the rink when viewing the rink in TV view. The default is 0.0

  • rink_updates (dict): A dictionary of updated parameters to use for the hockey rink. 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"

  • rink_params (dict): A dictionary containing the following parameters of the rink:

    • rink_length (float): The full length of the rink. Length is defined as the distance between the inner edge of the boards behind each goal at its widest point
    • rink_width (float): The full width of the rink. Width is defined as the distance between the inner edge of the boards between the team bench and the penalty box on the other side of the ice
    • rink_units (str): The units with which to draw the rink
    • corner_radius (float): The radius of the circle that comprises the rink's corners
    • board_thickness (float): The thickness of the boards. This is to give the boundary of the rink a clearer-to-see definition, although only the inner edge of the boards is considered in play and the boundary of the rink
    • referee_crease_radius (float): The outer radius of the semi-circle that comprises the referee's crease
    • nzone_length (float): The length of the neutral zone, measured from the interior edges of the zone lines (blue lines)
    • goal_line_to_boards (float): The x position of the center of the right-hand goal line relative to the boards behind the right-hand goal
    • major_line_thickness (float): The thickness of the major lines on the ice surface. Major lines are considered to be the center line (red line) and zone lines (blue lines)
    • minor_line_thickness (float): The thickness of the minor lines on the ice surface. Minor lines are those such as goal lines, hash marks, faceoff markings, or circle thicknesses
    • faceoff_circle_radius (float): The radius of the faceoff circles, both center and non-center, on the ice
    • center_faceoff_spot_radius (float): The radius of the center faceoff spot on the ice
    • center_faceoff_spot_gap (float): The gap in the center line that surrounds the center faceoff spot. This is measured between the inner edges of the two halves of the center line
    • noncenter_faceoff_spot_radius (float): The radius of the non-centered faceoff spots on the ice. These are in the defensive, neutral, and offensive zones
    • nzone_faceoff_spot_to_zone_line (float): The x position of the right-side faceoff spots in the neutral zone relative to the neutral-zone side of the zone (blue) line
    • odzone_faceoff_spot_to_boards (float): The distance (in the x direction) from the end of the rink to the center of the defensive/offensive zone faceoff spot
    • noncenter_faceoff_spot_y (float): The y position of the upper faceoff spots in the defensive, neutral, and offensive zones on the ice
    • noncenter_faceoff_spot_gap_width (float): The gap between the interior edge of a non-centered faceoff spot ring and the stripe running across it
    • hashmark_width (float): The width of the hashmarks on the exterior of the defensive and offensive faceoff circles. Note that width refers to a distance solely in the y direction
    • hashmark_ext_spacing (float): The exterior horizontal spacing between the hashmarks on the exterior of the defensive and offensive faceoff circles. Note that this is solely in the x direction
    • faceoff_line_dist_x (float): The distance from the center of the defensive and offensive faceoff spot to the left-most edge of the upper-right faceoff line
    • faceoff_line_dist_y (float): The distance from the center of the defensive and offensive faceoff spot to the bottom edge of the upper-right faceoff line
    • faceoff_line_length (float): The exterior length of the faceoff line
    • faceoff_line_width (float): The exterior width of the faceoff line
    • has_trapezoid (bool): Indicator of whether or not the rink has a goalkeeper's restricted area (trapezoid) behind each goal
    • short_base_width (float): The exterior base-width of the trapezoid (should it exist) that lies along the goal line
    • long_base_width (float): The exterior base-width of the trapezoid (should it exist) that lies along the boards
    • goal_crease_style (str): The style of goal crease to implement. Viable options are:
      • nhl98 (the current iteration of the NHL goal crease.): This is what is used for most professional leagues
      • nhl92 (the previous iteration of an NHL goal crease. It): is drawn as a semi-circle with two L-shaped notches at the edge of the crease intersecting the semi-circle
      • ushl1 (the current iteration of a USA Hockey goal): crease. This is what is currently used in the USHL (United States Hockey League)
    • goal_crease_radius (float): The radius of the rounded portion of the goal crease, as taken from the center of the goal line
    • goal_crease_length (float): The distance from the center of the goal line to the start of the arc of the goal crease
    • goal_crease_width (float): The exterior width of the goal crease
    • goal_crease_notch_dist_x (float): The distance from the center of the goal line to the notch (if one exists) in the goal crease
    • goal_crease_notch_width (float): The width of the notch (if one exists) in the goal crease
    • goal_mouth_width (float): The interior distance between the goalposts
    • goal_back_width (float): The exterior distance between the widest part of the goal frame's footprint
    • goal_depth (float): The depth of the goal frame from the center of the goal line to the exterior of the back pipe of the goal frame
    • goal_post_diameter (float): The diameter of the posts of the goal frame
    • goal_radius (float): The interior radius of the goal frame
    • bench_length (float): The exterior length of a single team's bench area
    • bench_depth (float): The interior depth off the boards of a single team's bench area
    • bench_separation (float): The separation between the two teams' bench areas
    • penalty_box_length (float): The interior length of a single penalty box
    • penalty_box_depth (float): The interior depth off of the boards of a single team's penalty box
    • penalty_box_separation (float): The distance that separates each team's penalty box area. This should be equivalent to the length of the off-ice officials' box

Leagues​

Each class below is a HockeyRink with that league's rule-book dimensions.

Classleague_codeDescription
AHLRinkahlA subclass of HockeyRink specific to the AHL.
ECHLRinkechlA subclass of HockeyRink specific to the ECHL.
IIHFRinkiihfA subclass of HockeyRink specific to the IIHF.
PHFRinkphfA subclass of HockeyRink specific to the PHF.
NCAARinkncaaA subclass of HockeyRink specific to the NCAA.
NHLRinknhlA subclass of HockeyRink specific to the NHL.
NWHLRinknwhlA subclass of HockeyRink specific to the NWHL.
OHLRinkohlA subclass of HockeyRink specific to the OHL.
QMJHLRinkqmjhlA subclass of HockeyRink specific to the QMJHL.
USHLRinkushlA subclass of HockeyRink specific to the USHL.
PWHLRinkpwhlA subclass of HockeyRink specific to the PWHL.

Methods​

draw​

HockeyRink.draw(ax = None, display_range = 'full', xlim = None, ylim = None, rotation = None)

Draw the rink.

Parameters​

  • ax (matplotlib.Axes): An axes object onto which the plot can be drawn. If None is 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 ice surface
    • "in bounds only": The full in-bounds area of the rink
    • "in_bounds_only": The full in-bounds area of the rink
    • "offense": the offensive (TV-right) half of the ice surface
    • "offence": the offensive (TV-right) half of the ice surface
    • "defense": the defensive (TV-left) half of the ice surface
    • "defence": the defensive (TV-left) half of the ice surface
    • "nzone": the neutral zone (the area between the zone lines)
    • "neutral: the neutral zone (the area between the zone lines)
    • "neutral_zone": the neutral zone (the area between the zone lines)
    • "neutral zone": the neutral zone (the area between the zone lines)
    • "ozone": the offensive zone. This is the area (TV-right) of the neutral zone
    • "offensive_zone: the offensive zone. This is the area (TV-right) of the neutral zone
    • "offensive zone: the offensive zone. This is the area (TV-right) of the neutral zone
    • "attacking_zone: the offensive zone. This is the area (TV-right) of the neutral zone
    • "attacking zone: the offensive zone. This is the area (TV-right) of the neutral zone
    • "dzone: the defensive zone. This is the area (TV-left) of the neutral zone
    • "defensive_zone: the defensive zone. This is the area (TV-left) of the neutral zone
    • "defensive zone: the defensive zone. This is the area (TV-left) of the neutral zone
    • "defending_zone: the defensive zone. This is the area (TV-left) of the neutral zone
    • "defending zone: the defensive zone. This is the area (TV-left) of the neutral zone

    The default is "full"

  • xlim (float or tuple of floats or None): The display range in the x direction to be used. If a single float is provided, this will be used as the lower bound of the x coordinates to display and the upper bound will be the +x end of the boards. If a tuple, the two values will be used to determine the bounds. If None, then the display_range will be used instead to set the bounds. The default is None

  • ylim (float or tuple of floats or None): The display range in the y direction to be used. If a single float is provided, this will be used as the lower bound of the y coordinates to display and the upper bound will be the +y side of the rink. If a tuple, the two values will be used to determine the bounds. If None, then the display_range will be used instead to set the bounds. The default is None

  • rotation (float or None): Angle (in degrees) through which to rotate the rink when drawing. If used, this will set the class attribute of _rotation. A value of 0.0 will correspond to a TV view of the rink, where +x is to the right and +y is on top. The rotation occurs counter clockwise. The default is None

cani_plot_leagues​

HockeyRink.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 is None, this will display all leagues that do come shipped with sportypy. The default is None

Returns​

  • Nothing, but a message will be printed out:

cani_color_features​

HockeyRink.cani_color_features()

Determine what features of the rink 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​

HockeyRink.cani_change_dimensions()

Determine what features of the rink can be re-parameterized.

This function is a helper function for the user to aid in customizing a rink'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 rink dimensions as a starting point

Returns​

  • Nothing, but a message will be printed out:

update_colors​

HockeyRink.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 (see cani_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_rink_params​

HockeyRink.update_rink_params(rink_param_updates = {}, *args, **kwargs)

Update the rink's defining parameters.

This method should primarily be used in cases when plotting a league not currently supported by sportypy

Parameters​

  • rink_updates (dict): A dictionary where the keys correspond to the name of the parameter of the rink that is to be updated (see cani_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​

HockeyRink.reset_colors()

Reset the features of the rink 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_rink_params​

HockeyRink.reset_rink_params()

Reset the features of the rink to their default parameterizations.

The rink parameters can be passed at the initial instantiation of the class via the rink_updates parameter, and through the update_rink_params() method, these can be changed. This method allows the feature parameterization to be reset to their default values after experiencing such a change