Visualising Football Tracking Data with Bokeh Server
How to create an interactive football plot for tracking data with bokeh server.
Last Thursday I listened to the first episode of Friends of Tracking where David Sumpter (@Soccermatics), @JaviOnData, @AlexThomasTheFA, Suds Gopaladesikan, @PeraltaFran23 and @pascal_bauer had the great idea to “give back during difficult times”. They will provide open lectures on football analytics explaining how they work inside clubs and national teams on their Youtube channel. As the name of their group suggests the group was initiated when tracking data became available in football and they recognized that everyone was working on the same problems and code. Because David Sumpter also mentioned that he tries to get some free tracking data of the Swedish league I thought that it might be a good idea to share a repository I found that can be used to easily visualize tracking data in a Jupyter notebook and start from there instead of implementing the visualization. It is written in Python and uses bokeh for the interaction. The nice thing is that it already has features to show Voronoi cells and convex hulls of both teams.
You can find the code at https://github.com/seidlr/Game-Animation and follow the instructions in the Readme
.
Here is a short summary if you already have Anaconda installed:
- Clone the repository
git clone https://github.com/seidlr/Game-Animation
- Change the directory
cd Game-Animation
- Create the conda environment
conda env update
This creates a conda environment called
game-animation
. - Activate the environment
conda activate game-animation
- And finally start the jupyter notebook server
jupyer notebook
- Select the
Soccer_example.ipynb
and run the code cells.
Following the instructions in the notebook you can easily visualise and animate tracking data. It might look like this:
Using the code you can actually focus your time on more valueable projects than building the visualisation. Here are some ideas to get started.
Possible extensions
- Color the Voronoi cells by team in red and blue.
- Use
sklearn
K-means on thex
values to find three clusters for attack, midfield and defense. - Draw lines between the players in each of the clusters as shown here:
- Count all “line-breaking” passes
Note
I have just forked this repository from https://github.com/samirak93/Game-Animation
. The code was not written by me. I only made some small changes to make it easier to use:
- I’ve cleaned up unneccesary folders like
__pycache__
and.ipynb_checkpoints
. - I’ve added a
.gitignore
file to keep the repository clean. - I’ve added an
environment.yml
file such that you can install all necessary requirements to run the notebooks. - I’ve changed the calculation of the convex hull of teams to not include the goalkeeper.