Blog of Random Thoughts and Pictures

Plotting actions on a pitch

February 14th, 2021

Purpose

The second element to work on via this course is Plotting actions on a pitch and the purpose is to

  • Loading match data and finding all the shots
  • Plotting shots on the pitch and highlighting goals.
  • Plotting expected goals
  • Plotting passes

The code needed for this lecture is also available at the Github SoccermaticsForPython repo.

Set up

Under the organisation on Github called mmoffoot I used my fork of the SoccermaticsForPython repo into the mmoffoot area.

Then re-used the branch called ‘week1’ covering the changes I had made as of week1 of the course.

As mentioned before I placed the StatsBomb data in a directory higher and then just add a soft link to the source data within the ‘Statsbomb’ folder of this project.

What was coded

This second exercise concentrated on the England vs Sweden Womens World Cup 2019 match and the exercise asked that I :

  1. Create a dataframe of passes which contains all the passes in the match.
  2. Plot the start point of every Sweden pass. Attacking left to right.
  3. Plot only passes made by Caroline Seger (she is Sara Caroline Seger in the database)
  4. Plot arrows to show where the passes went

I made the code changes to 2PlotShotsAndPasses.py and run the code as

python3 2PlotShotsAndPasses.py

The output from this exercise were mainly images, which was nice.

The code provided from the original repo had shots and goals defined for display, and also a nice feature where the size of the circle represented the expected goal (xG) rating of the shot, as calculated by StatsBomb. This xG thing is covered in more depth a little later in the course, but in general terms my understanding is that xG is the probability of that shot being a goal, the higher the xG the more likely that should should have been a goal.

Therefore in the plot, a solid colour with a name is a goal and the less visable circles are shots that were taken but did not end up as a goal.

Figure 1: Shots and Goals England vs Sweden Womens World Cup 2019.

 

I have a thing about the pitch being green, with markings as white, so that was the one code change I made to this original code. This caused a slight issue with the goals scored by England as they played in white, I made their shots in white and the penalty spot is white. All of this means that it looks like a goal was scored by England from the penalty spot, but the goal scorer is not named. For now I think I’ll leave it as is.

As for the football analysis, there’s 6 shots on goal from within the box for Sweden, with 2 of those chances having a high xG, but were not goals, and one of the goals scored by Eva Jakobsson looks like it was a tough chance to convert, but she managed it. England only had 4 shots on goal from within the box, and even had a chance with a larger xG but didn’t score from it.

Originating Passes

Next up, the creation of a dataframe of passes was relatively straight forward as the StatsBomb data provides a ‘type_name’ of Pass within the data set so they were easy enough to extract. So the first real plot I have ever created is all the originating position of passes of the match for both Sweden and England, with Sweden playing from left to right. Also added a little text at the bottom to highlight the data came from StatsBomb.

Figure 2: Originating Position of Passes in the England vs Sweden Womens World Cup 2019.

 

That image is a bit of a mess, as in hard to offer any football analysis, so here’s just the Swedish passes.

SWEpasses
Figure 3: Originating Position of Passes in the England vs Sweden Womens World Cup 2019.

 

Now this is a little bit more interesting, no passes by Sweden in with the opposition box.

Passes made by Caroline Seger

Next up, passes made by Caroline Seger (she is Sara Caroline Seger in the database), and for this filtering out by ‘player_name’ is not too hard with the StatsBomb data.

SWEpassesSCS
Figure 4: Originating Position of Passes by Caroline Seger (SWE) in the England vs Sweden Womens World Cup 2019.

 

Given the plot, there is a lot of midfield play by Caroline Seger and of course the next step of plotting arrows to show where the passes went would really add context to this play.

Now to verify that the code I have written for the directional arrows is correct I went searching for video footage of the match, and low and behold, on YouTube there are a set of full match videos for the Womens World Cup 2019 taken from the tactical camera from behind one of the goals. Thankfully the England vs Sweden match is up there too. Now I found it really hard to pick out Caroline Seger, but I did find it easier to identify Rut Hedvig Lindahl, the Swedish goal keeper, and therefore I picked minute 11 (at random) to see if I could correlate the pass on the video and the pass on my plotted pitch.

passRHL
Figure 5: Match footage of pass by Rut Hedvig Lindahl (SWE) in the England vs Sweden Womens World Cup 2019.

 

At this very period, this action was a throw out pass by Rut Hedvig Lindahl, so quite distinctive.

SWEpassesdirectionRHL
Figure 5: Plot of pass by Rut Hedvig Lindahl (SWE) in the England vs Sweden Womens World Cup 2019.

 

And from my code. Well there was a little gashing of teeth. The tutorial video that goes with this session indicated a different result, with code that was slightly different but thankfully this was corrected by the lecturer at a later date, and therefore I was on the right track. Just goes to show obtaining some sort of footage from a match can help with these things.

So finally we have the plot I was looking for in this whole session.

Figure 4: Passes by Caroline Seger (SWE) in the England vs Sweden Womens World Cup 2019.

 

From a football analysis view point Caroline Seger was mentioned in the Swedish line up as taking up the Left Defensive Midfield position, and the passes she made show she did indeed play that role, with a preference to progress the ball towards the opposition goal, with one incisive ball into the opposition box.

What was learned

The main take aways, it was great to learn how plotting the direction of the pass with arrows for a player is important, along with verifying a few of the passes via match footage, if at all possible. I know not all matches will have the tactical camera, but more often than not for the higher tier matches there’s footage of a goal or two to be found.

Post Update:

Thanks to Mike for reviewing the content and for rightly pointed out that I had the wrong image in place for the directional passes of Caroline Seger, and the coordinates for England passes was slightly off. Images and associated code have been updated.

 

Handling StatsBomb Event Data

February 7th, 2021

Yes I did have a blog post back in September 2020, highlighting that I was undertaking the Uppsala University course “Mathematical Modelling of Football” which overtook my time and life in Q4 2020. In completing the course I’m finally getting my head up in 2021 to record all my notes and code and to take a journey to share those notes as I go down through each section and sub-section of the course.

So here’s the first of hopefully many notes from the course, which were originally written in Asciidoc.

 

Purpose of Handling Event Data

The first element to work on via this course is Handling Event Data and the purpose is to learn how to :-

  • Download code and data
  • Organise working folder
  • Load in data from a json file.
  • Using ‘for’ loops and ‘if’ statements
  • Identify specific matches in Statsbomb data

The code needed for this lecture is available at the Github SoccermaticsForPython repo.

Set up

Created a new organisation on Github called mmoffoot standing for Mathematical Modelling of Football. The purpose is to fork the Github projects used in the course to track my own changes to those repos.

First up is a fork of the SoccermaticsForPython repo into the mmoffoot area.

Then created a branch called ‘week1’ covering the changes I had made as of week1 of the course.

The next little hurdle here is the loading of the Statsbomb data. It’s really in another repo on Github called statsbomb / open-data and in order to always have access to the StatsBomb data within this repo was going to set up a git submodule for this repo. This means that any time in the future when this repo is cloned (new) then it has to be done with the recursive command switch.

However then I noted that the StatsBomb data is over 3Gb in size and that it doesn’t really make sense have a couple of copies of this data on the one machine so I just placed it in a directory higher.I then just add a soft link to the source data within the ‘Statsbomb’ folder.

ln -s ../../statsbomb-opendata/data .

Also modified the README file to point this out.

What was coded

The first exercise is to

  1. Edit the code to print out the result list for the Mens World cup
  2. Edit the code to find the ID for England vs. Sweden
  3. Write new code to write out a list of just Sweden’s results in the tournament.

I made the code changes to 1LoadInData.py and run the code as

python3 1LoadInData.py

The output reads

The match between Croatia and Denmark finished 1 : 1
The match between Australia and Peru finished 0 : 2
.........
.........
The match between Spain and Russia finished 1 : 1
The match between Croatia and England finished 2 : 1
The Sweden match between Mexico and Sweden finished 0 : 3
The Sweden match between Sweden and South Korea finished 1 : 0
The Sweden match between Sweden and Switzerland finished 1 : 0
Sweden vs England has id:8651
The Sweden match between Sweden and England finished 0 : 2
The Sweden match between Germany and Sweden finished 2 : 1

I think the exercise is complete.

What was learned

Learning how to extract match results from the StatsBomb open data is important, and being able to read in the StatsBomb open data is great because at the time of writing it has a number of competitions covered in it.

  • International Mens FIFA World Cup 2018 (competition_id=43)
  • Europe Champions League 2018/2019
  • Europe Champions League 2017/2018
  • Europe Champions League 2016/2017
  • Europe Champions League 2015/2016
  • Europe Champions League 2014/2015
  • Europe Champions League 2013/2014
  • Europe Champions League 2012/2013
  • Europe Champions League 2011/2012
  • Europe Champions League 2010/2011
  • Europe Champions League 2009/2010
  • Europe Champions League 2008/2009
  • Europe Champions League 2006/2007
  • Europe Champions League 2004/2005
  • Europe Champions League 2003/2004
  • Europe Champions League 1999/2000
  • Spain La Liga 2018/2019
  • Spain La Liga 2017/2018
  • Spain La Liga 2016/2017
  • Spain La Liga 2015/2016
  • Spain La Liga 2014/2015
  • Spain La Liga 2013/2014
  • Spain La Liga 2012/2013
  • Spain La Liga 2011/2012
  • Spain La Liga 2010/2011
  • Spain La Liga 2009/2010
  • Spain La Liga 2008/2009
  • Spain La Liga 2007/2008
  • Spain La Liga 2006/2007
  • Spain La Liga 2005/2006
  • Spain La Liga 2004/2005
  • England Premier League 2003/2004
  • International Women’s World Cup 2019 (competition_id=72)
  • United States of America NWSL (Female) 2018
  • England FA Women’s Super League 2019/2020
  • England FA Women’s Super League 2018/2019