Tennis#

Tennis is currently supported for the following leagues (in alphabetical order):

Extension of the BaseSurfacePlot class to create a tennis court.

This is a second-level child class of the BaseSurface class, and as such will have access to its attributes and methods. sportypy will ship with pre-defined leagues that will have their own subclass, but a user can manually specify their own court parameters to create a totally-customized court. The court’s features are parameterized by the basic dimensions of the court, which comprise the attributes of the class.

@author: Ross Drucker

class sportypy.surfaces.tennis.TennisCourt(league_code='', court_updates={}, color_updates={}, rotation=0.0, x_trans=0.0, y_trans=0.0, units='default', **added_features)#

A subclass of BaseSurfacePlot to make a generic tennis court.

This allows for the creation of the tennis 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 tennis 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.

league_code#

The league for which the plot should be drawn. This is case-insensitive but should be the shortened name of the league (e.g. “International Tennis Federation” should be either “ITF” or “itf”). The default is an empty string

Type:

str

rotation#

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

Type:

float

x_trans#

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

Type:

float

y_trans#

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

Type:

float

court_updates#

A dictionary of updated parameters to use for the tennis court. The default is an empty dictionary

Type:

dict

color_updates#

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

Type:

dict

units#

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". The default is "default"

Type:

str

court_params#

A dictionary containing the following parameters of the court:

  • court_lengthfloat

    The length of the court in the court’s specified units

  • singles_widthfloat

    The width of a singles court in the court’s specified units

  • doubles_widthfloat

    The width of a doubles court in the court’s specified units

  • serviceline_distancefloat

    The distance from the net to the outer edge of the serviceline (the line in front of which a serve must land)

  • center_serviceline_lengthfloat

    The length of the center serviceline

  • center_mark_lengthfloat

    The distance that the center mark on the baseline protrudes forward from its anchor point at the back edge of the baseline

  • net_lengthfloat

    The length of the net, from post to post, in the court’s specified units

  • line_thicknessfloat

    The thickness of the lines of the court in the court’s specified units

  • backstop_distancefloat

    The distance from the back edge of the baseline to the barrier behind it in the court’s specified units

  • sidestop_distancefloat

    The distance from the outer edge of the sideline to the barrier that runs parallel to it in the court’s specified units

Type:

dict

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

Return type:

Nothing, but a message will be printed out

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

Return type:

Nothing, but a message will be printed out

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

Return type:

Nothing, but a message will be printed out

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

    • "serve": The serving half of the court

    • "serving": The serving half of the court

    • "servinghalf": The serving half of the court

    • "servicehalf": The serving half of the court

    • "serving_half": The serving half of the court

    • "service_half": The serving half of the court

    • "service half": The serving half of the court

    • "receive": The receiving half of the court

    • "receiving": The receiving half of the court

    • "receivinghalf": The receiving half of the court

    • "receiving_half": The receiving half of the court

    • "receiving half": The receiving half of the court

  • 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`` upper touchline. 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 counter clockwise. The default is None

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()#

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

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

Return type:

Nothing, but the class is re-instantiated with the updated colors

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

Return type:

Nothing, but the class is re-instantiated with the updated parameters