Function Repository Resource:

SportsFieldGraphics

Source Notebook

Display information on the fields of play for various popular sports

Contributed by: Jon McLoone

ResourceFunction["SportsFieldGraphics"]["sport"]

displays the standard markings of the pitch for "sport".

ResourceFunction["SportsFieldGraphics"]["sport",gr]

displays the standard markings of the pitch for "sport" together with Graphics gr.

Details and Options

ResourceFunction["SportsFieldGraphics"] currently supports the following sports: "AmericanFootball", "Badminton", "Baseball", "Basketball", "Cricket", "Croquet", "Darts", "FieldHockey", "Football", "IceHockey", "Judo", "Karate", "Lacrosse", "Polo", "RugbyLeague", "RugbyUnion", "Squash", "TableTennis", "Tennis" and "Volleyball".
The list of supported sports can be retrieved by evaluating ResourceFunction["SportsFieldGraphics"][].
In addition to standard Graphics options, the following options are supported:
"Units""Meters"unit system used for coordinates
"Length"Automaticthe length of the pitch for pitches that have variable sizes
"Width"Automaticthe width of the pitch for pitches that have variable sizes
"PitchFontStyle"Automaticfont information for text in pitch markings
BackgroundAutomaticbackground color or Texture for the pitch, usually dark green
"LineStyle"Automaticstyle for pitch markings, usually white
"PitchOrigin"{Center,Center}where {0, 0} lies on the pitch

Examples

Basic Examples (1) 

Create a blank sports pitch:

In[1]:=
ResourceFunction["SportsFieldGraphics"]["Tennis"]
Out[1]=

Scope (4) 

Combine the pitch with other graphics:

In[2]:=
ResourceFunction["SportsFieldGraphics"]["Tennis", ListPlot[{{5.885, 0.3901}, {6.078, 0.8065}, {5.476, 0.789}, {5.037, 0.6506}, {6.076, 3.568}, {5.313, 3.757}, {5.178, 3.289}, {5.663, 3.167}, {6.055, 2.958}, {7.086, 4.352}, {6.892, 0.1368}, {6.771, 2.968}}, PlotStyle -> Blue]]
Out[2]=

Any Graphics object can be combined with SportsFieldGraphics:

In[3]:=
ResourceFunction["SportsFieldGraphics"]["Football", SmoothDensityHistogram[CompressedData["
1:eJw1UwlIVFEUHaTc2kdtQmRScwsx0XEcHcf5Z+aPf/5MU6FZVESZWVRIRdm+
G1HRnqQtRLSaFbZaUVFPW2knBLNsMyr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7
uqVSYu9HPeisodccLrF5VK+Yvx/+ATteFoE=
"], ColorFunction -> (Blend[{RGBColor[0, 2/3., 0], Yellow}, #] &), PlotRange -> {{-53, 53}, {-42, 42}}]]
Out[3]=

A range of sports is supported:

In[4]:=
Labeled[ResourceFunction["SportsFieldGraphics"][#], #] & /@ ResourceFunction["SportsFieldGraphics"][]
Out[4]=

You can specify the sport using a "Sport" Entity:

In[5]:=
ResourceFunction["SportsFieldGraphics"][
 Entity["Sport", "AmericanFootball"]]
Out[5]=

Options (9) 

Background (2) 

Where pitches have multiple background colors, you can provide Background as a list:

In[6]:=
ResourceFunction["SportsFieldGraphics"]["AmericanFootball", Background -> {Green, Blue}]
Out[6]=

Background can also be set to a Texture, which will fill the field of play plus 10%:

In[7]:=
ResourceFunction["SportsFieldGraphics"]["Basketball", Background -> Texture[ExampleData[{"ColorTexture", "GoldenOak"}]]]
Out[7]=

Length (1) 

Some sports do not prescribe exact dimensions. You can use "Length" and "Width" to override the default values:

In[8]:=
ResourceFunction["SportsFieldGraphics"]["Cricket", "Length" -> Quantity[65, "Yards"], "Width" -> Quantity[90, "Yards"], Axes -> True, "Units" -> "Feet"]
Out[8]=
In[9]:=
ResourceFunction["SportsFieldGraphics"]["Cricket", "Length" -> Quantity[15, "Yards"], "Width" -> Quantity[90, "Yards"], Axes -> True, "Units" -> "Feet"]
Out[9]=

LineStyle (1) 

Pitch line styles can be specified:

In[10]:=
ResourceFunction["SportsFieldGraphics"]["Basketball", "LineStyle" -> Directive[Thick, Blue]]
Out[10]=

PitchFontStyle (1) 

Use "PitchFontStyle" to change the style of any text in a pitch:

In[11]:=
ResourceFunction["SportsFieldGraphics"]["AmericanFootball", "PitchFontStyle" -> {FontFamily -> "Times", FontSlant -> Italic, FontSize -> Scaled[0.05]}]
Out[11]=

PitchOrigin (1) 

The default origin is in the center of the pitch, but you can change this with "PitchOrigin":

In[12]:=
ResourceFunction["SportsFieldGraphics"]["Football", Graphics[], Axes -> True, "PitchOrigin" -> {Left, Bottom}]
Out[12]=

Units (2) 

The default unit system for sports pitches is "Meters":

In[13]:=
ResourceFunction["SportsFieldGraphics"]["Football", Axes -> True]
Out[13]=

You can change this with the option "Units":

In[14]:=
ResourceFunction["SportsFieldGraphics"]["Football", Graphics[], Axes -> True, "Units" -> "Feet"]
Out[14]=

Width (1) 

Some sports do not prescribe exact dimensions. You can use "Length" and "Width" to override the default values. If you exceed maximum or minimum sizes allowed for a sport, SportsFieldGraphic will use the closest allowed value:

In[15]:=
ResourceFunction["SportsFieldGraphics"]["Cricket", "Length" -> Quantity[90, "Yards"], "Width" -> Quantity[65, "Yards"], Axes -> True, "Units" -> "Feet"]
Out[15]=

Applications (1) 

As well as visualizing sports analytics data in context, you can use graphics primitives to create sports-related diagrams:

In[16]:=
ResourceFunction["SportsFieldGraphics"]["Croquet", Graphics[{Yellow, Arrow[BSplineCurve@{{-12.19, 6.481}, {-7.729, 6.459}, {8.44, 6.397}, {10.89, 6.362}, {12.57, 4.569}, {12.75, -0.8702}, {11.05, -6.196}, {8.783, -6.53}, {-8.657, -6.658}, {-10.53, -6.434}, {-12.26, -3.666}, {-9.478, -0.1313}, {-6.191, 0.02759}, {-4.242, -0.1746}, {-0.6425, -2.082}, {6.171, -1.937}, {6.618, -0.03199}, {4.522, -0.04418}, {2.143, 0.1934}}]}],
 PlotLabel -> Style["Croquet hoop order", 20, White],
 PlotRange -> {{-17, 17}, {-15, 15}}]
Out[16]=

Possible Issues (2) 

The full play area is used by default:

In[17]:=
ResourceFunction["SportsFieldGraphics"]["Cricket"]
Out[17]=

For cricket, you may wish to use PlotRange to show only the pitch:

In[18]:=
ResourceFunction["SportsFieldGraphics"]["Cricket", PlotRange -> 12]
Out[18]=

If you specify settings for "Length" or "Width" that exceed maximum or minimum sizes allowed for a sport, SportsFieldGraphics will use the closest allowed value:

In[19]:=
ResourceFunction["SportsFieldGraphics"]["Cricket", "Length" -> Quantity[10, "Yards"], "Width" -> Quantity[9000, "Yards"], Axes -> True, "Units" -> "Feet"]
Out[19]=

Publisher

Jon McLoone

Version History

  • 1.3.1 – 05 July 2022
  • 1.3.0 – 19 January 2022

License Information