Blog of Random Thoughts and Pictures

Good Practice in Football Visualisation

April 25th, 2021

This is a review of a special guest lecture from Opta’s Peter McKeever were he gives some insights in to how to make better data visualisations.

In this video Peter covers:

  • Elements of Matplotlib
  • Under the Hood: rcParams
  • Layering objects with zorder in plots
  • Works through a real world example

The origin of the code is available on Github under the project “friends-of-tracking-viz-lecture” and worked through in this video.

Peter’s slides are available here in this PDF document. Peter also has an excellent blog with code and further examples.

Set up

Under the organisation on Github called mmoffoot I forked the “friends-of-tracking-viz-lecture” repo into the mmoffoot area.

Then I created a new branch called ‘tottenham’ in this area to cover the changes I made.

What was coded

This is another Jupyter Notebook, but this time I just could not get it to load up the highlight_text python library and so I had to create a bog standard Python programme to run through this code base.

Then I found that highlight_text has changed its interface slightly since Peter coded against it. For example in the Notebook there’s the line

htext.fig_htext(s.format(team,ssn_start,ssn_end),0.15,0.99,highlight_colors=[primary], highlight_weights=["bold"],string_weight="bold",fontsize=22, fontfamily=title_font,color=text_color)

I had to change it to

htext.fig_text(0.15,0.86,s.format(team,ssn_start,ssn_end),highlight_colors=[primary], highlight_weights=["bold"],fontweight="bold",fontsize=22, fontfamily=title_font,color=text_color)

Given that Peter McKeever has run through all the elements coded via the YouTube video and there’s an associated slide deck this is a really nice resource to get started on exact visual items and how to then code them up. Of course for devilment I’ve gone for a Tottenham theme for the final output.

Tottenham’s goal difference from 2010/2011 to 2019/2020

Peter also talks about the blog posts by Lisa Rost which are well worth a review on how to visualise data. He also gives a pointer towards Tim Bayer and his work doing some things for Fantasy premier league, all of which is excellent.

Finally there’s ThemePy which is being developed, it is a theme selector / creator and aesthetic manager for Matplotlib. This wrappers aim is to simplify the process of customising matplotlib plots and to enable users who are relatively new to python or matplotlib to move beyond the default plotting params we are given with matplotlib.