mplsoccer is a Python plotting library for drawing soccer / football pitches quickly in Matplotlib.
Project description
mplsoccer
mplsoccer is a Python library for drawing soccer/football pitches in Matplotlib and loading StatsBomb open-data.
Installation
Use the package manager pip to install mplsoccer.
pip install mplsoccer
Docs
Here are the docs for mplsoccer.
Quick start
Plot a StatsBomb pitch
from mplsoccer.pitch import Pitch
pitch = Pitch(pitch_color='grass', line_color='white', stripe=True)
fig, ax = pitch.draw()
Why mplsoccer exists
mplsoccer shares some of the tools I built for the OptaPro Analytics Forum. At the time there weren’t any open-sourced python tools. Now alternatives exist, such as matplotsoccer.
By using mplsoccer, I hope that you can spend more time building insightful graphics rather than having to learn to draw pitches from scratch.
Advantages of mplsoccer
mplsoccer:
- draws 7 different pitch types by changing a single argument, which is useful as there isn’t a standardised data format
- extends matplotlib to plot heatmaps, (comet) lines, footballs and rotated markers
- flips the data coordinates when in a vertical orientation so you don’t need to remember to flip them
- creates tidy dataframes for StatsBomb data, which is useful as most of the alternatives produce nested dataframes
License
Contributions
Contributions are welcome. It would be great to add the following functionality to mplsoccer:
- pass maps
- pass sonars
Examples to help others are also welcome for a gallery.
Please get in touch at rowlinsonandy@gmail.com or @numberstorm on Twitter.
Inspiration
mplsoccer was inspired by other people's work:
- Peter McKeever inspired the API design
- ggsoccer - a library for plotting pitches in R
- lastrow - often tweets animations from matches and the accompanying code
- fcrstats - tutorials for using football data
- fcpython - Python tutorials for using football data
- Karun Singh - tweets some interesting football analytics and visuals
- StatsBomb - great visual design and free open-data
- John Burn-Murdoch's tweet got me interested in football analytics
Recent changes
View the changelog for a full list of the recent changes to mplsoccer.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.