Blog of Random Thoughts and Pictures

Plotting actions on a pitch

February 14th, 2021


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 and run the code as


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.

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.

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.

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.

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.