Baseball#

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

Extension of the BaseSurfacePlot class to create a baseball field.

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 field parameters to create a totally-customized field. The field’s features are parameterized by the basic dimensions of the field, which comprise the attributes of the class.

@author: Ross Drucker

class sportypy.surfaces.baseball.BaseballField(league_code='', field_updates={}, color_updates={}, rotation=0.0, x_trans=0.0, y_trans=0.0, units='default', **added_features)#

A subclass of the BaseSurfacePlot class to make a baseball field.

This allows for the creation of the baseball field in a way that is entirely parameterized by the field’s baseline characteristics. By convention, TV view for baseball is identical to the view from the high home plate camera.

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 baseball field. The attributes needed to instantiate a particular league’s surface must be specified in the field_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. “Major League Baseball” should be either “MLB” or “mlb”). The default is an empty string

Type:

str

rotation_amt#

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 pitcher’s plate towards first base when viewing the field 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 back tip of home plate out towards center field when viewing the field in TV view. The default is 0.0

Type:

float

feature_colors#

A dictionary of coloring parameters to pass to the plot

Type:

dict

field_params#

A dictionary containing the following parameters of the field:

  • field_unitsstr

    The units of the field

  • left_field_distancefloat

    The straight-line distance from the back tip of home plate to the left field foul pole (along theta = -45°)

  • right_field_distancefloat

    The straight-line distance from the back tip of home plate to the right field foul pole (along theta = +45°)

  • center_field_distancefloat

    The straight-line distance from the back tip of home plate to straight-away center field (along theta = 0°)

  • baseline_distancefloat

    The distance of each baseline

  • running_lane_start_distancefloat

    The straight-line distance from the back tip of home plate to the start of the running lane

  • running_lane_depthfloat

    The straight-line distance from the outer edge of the first-base line to the outer edge of the running lane

  • running_lane_lengthfloat

    The straight-line length of the running lane measured from the point nearest home plate. As an example, if the base lines are 90 feet, and the running lane starts a distance of 45 feet down the line from the back tip of home plate, and extends 3 feet beyond first base, this parameter would be given as 48.0

  • pitchers_mound_center_to_home_platefloat

    The distance from the center of the pitcher’s mound to the back tip of home plate. NOTE: this does not necessarily align with the front edge of the pitcher’s plate

  • pitchers_mound_radiusfloat

    The radius of the pitcher’s mound

  • pitchers_plate_front_to_home_platefloat

    The distance from the front edge of the pitcher’s plate to the back tip of home plate

  • pitchers_plate_widthfloat

    The width of the pitcher’s plate (the dimension in the y direction)

  • pitchers_plate_lengthfloat

    The length of the pitcher’s plate (the dimension in the x direction)

  • base_side_lengthfloat

    The length of one side of a square base

  • home_plate_edge_lengthfloat

    The length of a full side of home plate

  • infield_arc_radiusfloat

    The distance from the front edge of the pitcher’s mound to the back of the infield dirt

  • base_anchor_to_infield_grass_radiusfloat

    The distance from the anchor point of a base to the circular cutout in the infield grass. The anchor point of a base is defined as the point used in the definition of the base paths. As an example, in MLB, the anchor point of first base would be the corner of the first base bag along the foul line on the side furthest from the back tip of home plate

  • line_widthfloat

    The thickness of all chalk lines on the field

  • foul_line_to_infield_grassfloat

    The distance from the outer edge of the foul line to the outer edge of the infield grass

  • foul_line_to_foul_grassfloat

    The distance from the outer edge of the foul line to the inner edge of the grass in foul territory

  • batters_box_lengthfloat

    The length of the batter’s box (in the y direction) measured from the outside of the chalk lines

  • batters_box_widthfloat

    The width of the batter’s box (in the x direction) measured from the outside of the chalk lines

  • batters_box_y_adjfloat

    The shift off of center in the y direction that the batter’s box needs to be moved to properly align

  • home_plate_side_to_batters_boxfloat

    The distance from the outer edge of the batter’s box to the outer edge of home plate

  • catchers_box_shapestr

    The shape of the catcher’s box. Currently-supported values are: - “rectangle” (default behavior) - “trapezoid” (see LittleLeagueField for example)

  • catchers_box_depthfloat

    The distance from the back tip of home plate to the back edge of the catcher’s box

  • backstop_radiusfloat

    The distance from the back tip of home plate to the interior edge of the backstop

  • home_plate_circle_radiusfloat

    The radius of the dirt circle surrounding home plate

Type:

dict

cani_change_dimensions()#

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

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

Return type:

Nothing, but a message will be printed out

cani_color_features()#

Determine what features of the field 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 baseball 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 sportypy11. 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 field.

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, optional) –

    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 surface

    • "infield": The infield portion of the baseball diamond

    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 field. 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` end of the field. 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 field 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 field, where +``x`` is to the right and +``y`` is on top. The rotation occurs counter clockwise

reset_colors()#

Reset the features of the field 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_field_params()#

Reset the features of the field to their default parameterizations.

The field parameters can be passed at the initial instantiation of the class via the field_updates parameter, and through the update_field_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_field_params(field_param_updates={}, *args, **kwargs)#

Update the field’s defining parameters.

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

Parameters:

field_updates (dict) – A dictionary where the keys correspond to the name of the parameter of the field 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