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()
Grids
from mplfooty.pitch import Pitch
pitch = Pitch(pitch_width=135, pitch_length=165)
fig, axs = pitch.grid(nrows = 2, ncols = 2, axis=False)
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)
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)
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)
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))
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)
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)
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
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.2.0.tar.gz
(22.3 kB
view details)
Built Distribution
mplfooty-0.2.0-py3-none-any.whl
(22.5 kB
view details)
File details
Details for the file mplfooty-0.2.0.tar.gz
.
File metadata
- Download URL: mplfooty-0.2.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 046366e86806ac3f68b15f4d7d9ff6e44e37c828944bf98db479f16ddd4b17cb |
|
MD5 | e57fb43fe443eb72ed71ce1e4718be46 |
|
BLAKE2b-256 | a95e1ac7f2fb88bdffdfc9f1efed8dde378fd72fafb7d5edb6293fb2558a7253 |
Provenance
File details
Details for the file mplfooty-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: mplfooty-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b04d6070ecb2bd87be74f0171dac16580eb60f1d94c19a83778c395ef86a3828 |
|
MD5 | d3fc663eac2a5f9e17742550ce420024 |
|
BLAKE2b-256 | 584d0f39926dffe96b23dc285a9ae5a8f403347e680666e287334b47bb65de6b |