Skip to main content

AFL pitch plotting using matplotlib

Project description

mplfooty

mplfooty is a Python library for plotting AFL charts in Matplotlib.

Heavily heavily inspired and copied from mplsoccer. Translated from soccer into AFL pitches for personal analysis.

Installation

Use the package manager pip to install mplfooty.

pip install mplfooty

Usage

Pitch Plotting

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165)
pitch.draw()

pitch

Grids

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165)
fig, axs = pitch.grid(nrows = 2, ncols = 2, axis=False)

pitch

Scatter

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165)
fig, ax = pitch.draw()
pitch.scatter(x=[25, 25, -25, -25], y=[-25, 25, -25, 25], ax=ax)

pitch

Kdeplot

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165, line_zorder=2)
fig, ax = pitch.draw()
x = np.random.uniform(low=-100/2, high=100/2, size=36)
y = np.random.uniform(low=-90/2, high=90/2, size=36)
pitch.kdeplot(x, y, ax=ax, thresh=0, fill = True, color = "red", levels=100)

pitch

Heatmap

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165, line_zorder=2, line_colour="grey", pitch_colour='black')
fig, ax = pitch.draw()
x = np.random.uniform(low=-165/2, high=165/2, size=1000)
y= np.random.uniform(low=-135/2, high=135/2, size=1000)
stats = pitch.bin_statistic(x, y, bins=(10, 8))
pitch.heatmap(stats, edgecolors="black", cmap="hot", ax=ax)

pitch

Hexbin

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165, line_zorder=2, line_colour="#000009")
fig, ax = pitch.draw()
x = np.random.uniform(low=-82.5, high=100.5, size=10000)
y= np.random.uniform(low=-82.5, high=67.5, size=10000)
pitch.hexbin(x, y, edgecolors = "black", ax=ax, cmap="Reds", gridsize=(10, 5))

pitch

Voronoi

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165)
fig, ax = pitch.draw()
x = np.random.uniform(low=-100/2, high=100/2, size=36)
y = np.random.uniform(low=-90/2, high=90/2, size=36)
teams = np.array([0] * 18 + [1] * 18)
pitch.scatter(x[teams == 0], y[teams == 0], color = "red", ax=ax)
pitch.scatter(x[teams == 1], y[teams == 1], color = "blue", ax=ax)
team1, team2 = pitch.voronoi(x, y, teams)
team1_poly = pitch.polygon(team1, ax=ax, color = "red", alpha=0.3)
team2_poly = pitch.polygon(team2, ax=ax, color = "blue", alpha=0.3)

pitch

Goal Angles

from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165)
fig, ax = pitch.draw()
pitch.goal_angle(50, 30, color = "red", alpha=0.3, ax=ax)

pitch

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mplfooty-0.3.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mplfooty-0.3.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file mplfooty-0.3.0.tar.gz.

File metadata

  • Download URL: mplfooty-0.3.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for mplfooty-0.3.0.tar.gz
Algorithm Hash digest
SHA256 898761254889ae4c13e5fec35b5887fe245a2a902baea68691921153cbc92edf
MD5 e44cd3ced3017f14e46ff142c5c50703
BLAKE2b-256 8023e87feacea37d3190741873113e8ed316d835397385430ea7f0e0640b2a52

See more details on using hashes here.

File details

Details for the file mplfooty-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mplfooty-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for mplfooty-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1aa4864b7a98eba52e20a6ff555e97d961a1560cf60abe051e17cd52e0d659a2
MD5 9f0467a98786ee0683ca68118553a6f8
BLAKE2b-256 9dfc08b1397a49268c51f28d346ae45a55eb8228bbc288696300e47c58f977a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page