{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# xG Scatter Plots - League Two" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import matplotlib.ticker as ticker\n", "# import matplotlib.patheffects as path_effects\n", "import matplotlib.font_manager as fm\n", "# import matplotlib.colors as mcolors\n", "# from matplotlib import cm\n", "from highlight_text import fig_text, ax_text\n", "# from matplotlib.colors import LinearSegmentedColormap, NoNorm\n", "# from matplotlib import cm\n", "import matplotlib.gridspec as gridspec\n", "# import numpy as np\n", "\n", "from PIL import Image\n", "import urllib\n", "import json\n", "import os" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "font_path = \"../assets/fonts\"\n", "for x in os.listdir(font_path):\n", " for y in os.listdir(f\"{font_path}/{x}\"):\n", " if y.split(\".\")[-1] == \"ttf\":\n", " fm.fontManager.addfont(f\"{font_path}/{x}/{y}\")\n", " try:\n", " fm.FontProperties(weight=y.split(\"-\")[-1].split(\".\")[0].lower(), fname=y.split(\"-\")[0])\n", " except Exception:\n", " continue\n", "\n", "plt.style.use(\"../assets/stylesheets/soc_base.mplstyle\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read the data" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | match_id | \n", "date | \n", "referee | \n", "variable | \n", "value | \n", "venue | \n", "team_id | \n", "team_name | \n", "team_lineup | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "3916384 | \n", "2022-07-30 09:00:00 | \n", "Bobby Madden | \n", "xG_for | \n", "1.72 | \n", "H | \n", "8484 | \n", "Bradford City | \n", "4 - 2 - 3 - 1 | \n", "
1 | \n", "3916384 | \n", "2022-07-30 09:00:00 | \n", "Bobby Madden | \n", "xG_ag | \n", "0.21 | \n", "H | \n", "8484 | \n", "Bradford City | \n", "4 - 2 - 3 - 1 | \n", "
2 | \n", "3916381 | \n", "2022-07-30 09:00:00 | \n", "Thomas Kirk | \n", "xG_for | \n", "2.46 | \n", "H | \n", "10196 | \n", "Carlisle United | \n", "3 - 5 - 2 | \n", "
3 | \n", "3916381 | \n", "2022-07-30 09:00:00 | \n", "Thomas Kirk | \n", "xG_ag | \n", "0.28 | \n", "H | \n", "10196 | \n", "Carlisle United | \n", "3 - 5 - 2 | \n", "
4 | \n", "3916396 | \n", "2022-07-30 09:00:00 | \n", "Chris Pollard | \n", "xG_for | \n", "1.88 | \n", "H | \n", "8351 | \n", "Leyton Orient | \n", "4 - 3 - 3 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
423 | \n", "3916500 | \n", "2022-09-17 09:00:00 | \n", "Sam Purkiss | \n", "xG_ag | \n", "2.17 | \n", "A | \n", "8493 | \n", "Rochdale | \n", "4 - 2 - 3 - 1 | \n", "
424 | \n", "3916503 | \n", "2022-09-17 09:00:00 | \n", "Will Finnie | \n", "xG_for | \n", "0.31 | \n", "A | \n", "8488 | \n", "Hartlepool United | \n", "3 - 4 - 2 - 1 | \n", "
425 | \n", "3916503 | \n", "2022-09-17 09:00:00 | \n", "Will Finnie | \n", "xG_ag | \n", "1.46 | \n", "A | \n", "8488 | \n", "Hartlepool United | \n", "3 - 4 - 2 - 1 | \n", "
426 | \n", "3916502 | \n", "2022-09-17 09:00:00 | \n", "Ross Joyce | \n", "xG_for | \n", "0.49 | \n", "A | \n", "7946 | \n", "Harrogate Town | \n", "4 - 2 - 3 - 1 | \n", "
427 | \n", "3916502 | \n", "2022-09-17 09:00:00 | \n", "Ross Joyce | \n", "xG_ag | \n", "0.67 | \n", "A | \n", "7946 | \n", "Harrogate Town | \n", "4 - 2 - 3 - 1 | \n", "
428 rows × 9 columns
\n", "