mplsoccer

mplsoccer is a Python library for drawing soccer/football pitches in Matplotlib and loading StatsBomb open-data.

Quick start

Use the package manager pip to install mplsoccer.

pip install mplsoccer

Plot a StatsBomb pitch:

from mplsoccer.pitch import Pitch
pitch = Pitch(pitch_color='grass', line_color='white', stripe=True)
fig, ax = pitch.draw()
_images/sphx_glr_plot_quick_start_001.png

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:

  1. draws 7 different pitch types by changing a single argument, which is useful as there isn’t a standardised data format

  2. extends matplotlib to plot heatmaps, (comet) lines, footballs and rotated markers

  3. flips the data coordinates when in a vertical orientation so you don’t need to remember to flip them

  4. creates tidy dataframes for StatsBomb data, which is useful as most of the alternatives produce nested dataframes

License

MIT

Contributions

Contributions are welcome. It would be great to add the following functionality to mplsoccer:

  • pass maps

  • pass sonars

I would also welcome more examples in the gallery to help others.

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 is a library for plotting pitches in R

  • lastrow often tweets animations and the accompanying code

  • fcrstats has some great tutorials for using football data

  • fcpython also has some great tutorials in Python

  • Karun Singh tweets some interesting football analytics and visuals

  • StatsBomb has great visual designs and free open-data

  • John Burn-Murdoch’s tweet got me interested in football analytics

Indices and tables