Skip to main content

Basketball

from sportypy.surfaces.basketball import BasketballCourt

BasketballCourt​

A subclass of BaseSurfacePlot to make a generic basketball court.

This allows for the creation of the basketball court in a way that is entirely parameterized by the court'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 basketball court. The attributes needed to instantiate a particular league's surface must be specified in the court_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 Basketball Association" should be either "NBA" or "nba"). The default is an empty string

  • rotation_amt (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 basket when viewing the court 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 court when viewing the court in TV view. The default is 0.0

  • feature_colors (dict): A dictionary of coloring parameters to pass to the plot

  • court_params (dict): A dictionary containing the following parameters of the court:

    • court_length (float): The length of the court
    • court_width (float): The width of the court
    • line_thickness (float): The thickness of the lines of the court in the court's specified units
    • bench_side (str): The side, in TV view where the team benches are located
    • court_apron_endline (float): The thickness of the court's apron beyond the endline
    • court_apron_sideline (float): The thickness of the court's apron beyond the sideline
    • court_apron_to_boundary (float): The distance from the inner edge of the court apron to the outer edge of the court's boundary line (sideline and endline will be spaced the same)
    • center_circle_radius (list or float): The radius (radii) of the court's center circle(s) in the court's specified units. These should be measured from the center of the court to the outer edge of the circle. When providing a list (e.g. for the NBA), these values should go in decreasing order
    • division_line_extension (float): The distance that the division line extends beyond the sidelines. This may be omitted if the value is 0
    • basket_center_to_baseline (float): The distance from the center of the basket ring to the inner edge of the baseline
    • basket_center_to_three_point_arc (float): The distance from the cetner of the basket ring to the outer edge of the arc of the three point line
    • basket_center_to_corner_three (float): The distance from the center of the basket ring to the outer edge of the three-point line in the corner
    • backboard_face_to_baseline (float): The distance from the face of the backboard to the inner edge of the baseline
    • lane_length (float): The distance from the inner edge of the baseline to the center-court side of the free-throw lane in the court's specified units in TV view
    • lane_width (float): The distance from the outer edges of the free-throw lane when viewing the court in TV view
    • paint_margin (float): The distance from the painted area of the lane to the lane boundary lines
    • free_throw_circle_radius (float): The radius of the free-throw circle, measured from the center of the free-throw line, given
    • free_throw_line_to_backboard (float): The distance from the free-throw line to the face of the backboard
    • free_throw_circle_overhang (float): The arc length of any part of the free-throw circle that extends beyond the free-throw line
    • n_free_throw_circle_dashes (float): The number of dashes that comprise the free-throw circle
    • free_throw_dash_length (float): The arc length of each dash of the free-throw circle
    • free_throw_dash_spacing (float): The arc length of the gap between each dash of the free-throw circle
    • lane_space_mark_lengths (float or list of either lists or floats): The length (measurement in the baseline-to-free-throw-line direction) of lane space marks (blocks) of the free-throw lane
    • lane_space_mark_widths (float or list of either lists or floats): The widths (measurement in the sideline-to-sideline direction) of the lane space marks (blocks) of the free-throw lane in the court's specified units
    • lane_space_mark_separations (float or list of either lists or floats): The separations between each lane space mark in the court's specified dimensions. The first "spacing" measurement corresponds to the distance between the face of the backboard and the baseline-side edge of the first/"low" block
    • painted_area_visibility (bool or list of bools): Whether or not to show the painted area. This is particularly useful if more than one free-throw lane is specified (e.g. an NBA court with an NCAA lane drawn in addition to the NBA-sized lane)
    • lane_boundary_visibility (bool or list of bools): Whether or not to show the lane boundary. This is particularly useful if more than one free-throw lane is specified (e.g. an NBA court with an NCAA lane drawn in addition to the NBA-sized lane)
    • lane_space_mark_visibility (bool or list of bools): Whether or not to draw the lane space marks. This is particularly useful if more than one free-throw lane is specified (e.g. an NBA court with an NCAA lane drawn in addition to the NBA-sized lane)
    • lane_lower_defensive_box_marks_visibility (bool or list of bools): Whether or not to draw the lower defensive box markings that appear in the free-throw lane/painted area
    • baseline_lower_defensive_box_marks_int_sep (float): The interior separation between the lower defensive box markings on the baseline
    • baseline_to_lane_lower_defensive_box_marks (float): The interior distance from the inner edge of the baseline to the baseline-side edge of the lower defensive box markings located in the free-throw lane/painted area
    • lane_lower_defensive_box_marks_int_sep (float): The interior separation between the lower defensive box markings in the free-throw lane/painted area
    • lower_defensive_box_mark_extension (float): The distance that the lower defensive box markings extend from their anchor points
    • inbounding_line_to_baseline (float): The interior distance from the inner edge of the baseline to the baseline-side edge of the inbounding line in the court's specified units
    • inbounding_line_anchor_side (float): The side where the primary inbounding lines are located. This should be either 1.0 or -1.0, corresponding to the top or bottom of the court in TV view, respectively
    • inbounding_line_in_play_ext (float): The distance into the court (measured from the inner edge of the sideline) that the inbounding lines protrude into the court
    • inbounding_line_out_of_bounds_ext (float): The distance away from the court (measured from the outer edge of the sideline) that the inbounding lines protrude away the court
    • symmetric_inbounding_line (bool): Whether or not the inbounding lines are symmetric about the court
    • substitution_line_ext_sep (float): The external separation of the lines marking the substitution area
    • substitution_line_width (float): The distance away from the court (measured from the outer edge of the sideline) that the substitution lines protrude away from the court
    • team_bench_line_ext (float): The distance that the team bench line extends from its anchor point
    • restricted_arc_radius (float): The inner radius of the restricted arc in the court's specified units
    • backboard_width (float): The distance the backboard spans across the lane in the court's specified units. This is the left-to-right dimension of the backboard a free-throw shooter would see when shooting their free-throws
    • backboard_thickness (float): The thickness of the backboard. This is the observed thickness when viewing the court from a bird's eye view
    • basket_ring_inner_radius (float): The inner radius of the basket ring
    • basket_ring_connector_width (float): The dimension of the piece of the basket ring that connects the backboard to the basket ring. When viewing the court in TV view from above, this is the dimension in the y direction
    • basket_ring_connector_extension (float): The distance the basket ring's connector extends from the backboard into the free-throw lane
    • basket_ring_thickness (float): The thickness of the basket ring

Leagues​

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

Classleague_codeDescription
FIBACourtfibaA subclass of BasketballCourt specific to FIBA.
NBACourtnbaA subclass of BasketballCourt specific to the NBA.
NBAGLeagueCourtnba g leagueA subclass of BasketballCourt specific to the NBA G League.
NCAACourtncaaA subclass of BasketballCourt specific to the NBA.
NFHSCourtnfhsA subclass of BasketballCourt specific to the NFHS.
WNBACourtwnbaA subclass of BasketballCourt specific to the NBA.

Methods​

draw​

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

Draw the court.

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 court
    • "in bounds only": The full in-bound area of the court
    • "in_bounds_only": The full in-bound area of the court
    • "offense": The attacking/offensive half court
    • "offence": The attacking/offensive half court
    • "offensivehalfcourt": The attacking/offensive half court
    • "offensive_half_court": The attacking/offensive half court
    • "offensive half court": The attacking/offensive half court
    • "defense": The defensive half court
    • "defence": The defensive half court
    • "defensivehalfcourt": The defensive half court
    • "defensive_half_court": The defensive half court
    • "defensive half court": The defensive half court
    • "offensivekey": The attacking/offensive key
    • "offensive_key": The attacking/offensive key
    • "offensive key": The attacking/offensive key
    • "attackingkey": The attacking/offensive key
    • "attacking_key": The attacking/offensive key
    • "attacking key": The attacking/offensive key
    • "defensivekey": The defensive key
    • "defensive_key": The defensive key
    • "defensive key": The defensive key
    • "defendingkey": The defensive key
    • "defending_key": The defensive key
    • "offensivepaint": The attacking/offensive painted area
    • "offensive_paint": The attacking/offensive painted area
    • "attackingpaint": The attacking/offensive painted area
    • "attacking_paint": The attacking/offensive painted area
    • "offensivelane": The attacking/offensive painted area
    • "offensive_lane": The attacking/offensive painted area
    • "offensive lane": The attacking/offensive painted area
    • "attackinglane": The attacking/offensive painted area
    • "attacking_lane": The attacking/offensive painted area
    • "attacking lane": The attacking/offensive painted area
    • "defensivepaint": The defensive painted area
    • "defensive_paint": The defensive painted area
    • "defendingpaint": The defensive painted area
    • "defending_paint": The defensive painted area
    • "defensivelane": The defensive painted area
    • "defendinglane": The defensive painted area
    • "defending_lane": The defensive painted area
    • "defending lane": The defensive painted area

    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 court. 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 court. 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 court 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 court, where +x is to the right and +y is on top. The rotation occurs counterclockwise. The default is None

cani_plot_leagues​

BasketballCourt.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 basketball 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​

BasketballCourt.cani_color_features()

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

BasketballCourt.cani_change_dimensions()

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

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

Returns​

  • Nothing, but a message will be printed out:

update_colors​

BasketballCourt.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_court_params​

BasketballCourt.update_court_params(court_param_updates = {}, *args, **kwargs)

Update the court's defining parameters.

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

Parameters​

  • court_updates (dict): A dictionary where the keys correspond to the name of the parameter of the court 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​

BasketballCourt.reset_colors()

Reset the features of the court 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_court_params​

BasketballCourt.reset_court_params()

Reset the features of the court to their default parameterizations.

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