Skip to content

Guides

Premier League xG and shot maps in Python

Pull every shot a Premier League club took and conceded with x, y and xG, draw the shot map, get xG per 90 and goals against xG per player, and compare with the table.

Every script run against the live API on December 4, 2026. One full run: 29 credits.

This tutorial builds a Premier League xG report for one club with the StrikerAPI Python client. The example is Liverpool in 2026-27 (seasons are named by the year they start, so it is season=2026), through its first 13 league matches. It lists the club's matches, pulls every shot it took and conceded with its position, outcome and expected goals, draws them on a half pitch, works out xG for and against per 90 minutes and goals against xG for each player, and compares the club's xG with its place in the table.

Expected goals (xG) is the chance that a shot becomes a goal. Ours is a location model: it looks at where the shot was taken and whether it was a header, and nothing else. It does not see defenders, the goalkeeper or the pass that set the shot up. The last step comes back to what that means for how you read the numbers.

One full run costs 29 credits: 2 for the match list, 20 for two shot maps at 10, 2 for the table and 5 for every club's xG. The free 500 credits a month cover 17 full runs (493 credits). The script makes 5 requests, so it stays far under the 60 requests a minute limit.

1. Install the client and set your key

The client has no required dependencies. This tutorial uses pandas for tables and matplotlib for the shot map, which draws the pitch with a few shapes so it runs on any Python the client supports (3.9 or newer). The client reads your key from STRIKERAPI_API_KEY. If you prefer ready-made pitches, mplsoccer draws one and takes the same x and y once you convert them to metres or its own scale.

pip install "strikerapi[pandas]" matplotlib
export STRIKERAPI_API_KEY=your_key_here

2. List the club's matches this season

list_games returns a club's matches, newest first. status="final" keeps the ones that have been played, so the count is the number of matches the club has finished. The club can be given by abbreviation (LIV), name or id. The script reads the score from the club's side, whether it played at home or away, and saves the list for the later steps.

import numpy as np
from strikerapi import Client, to_dataframe

client = Client()  # reads STRIKERAPI_API_KEY
TEAM, SEASON = "LIV", 2026  # seasons are named by the year they start: 2026 is 2026-27

games = to_dataframe(client.list_games(team=TEAM, season=SEASON, status="final"), key="games")
home = games["home.abbrev"] == TEAM
games["venue_side"] = np.where(home, "H", "A")
games["opponent"] = np.where(home, games["away.abbrev"], games["home.abbrev"])
games["gf"] = np.where(home, games["home.score"], games["away.score"])
games["ga"] = np.where(home, games["away.score"], games["home.score"])
games = games.sort_values("date").reset_index(drop=True)
games[["game_id", "date", "venue_side", "opponent", "gf", "ga"]].to_csv("liverpool_matches.csv", index=False)

print(games[["date", "venue_side", "opponent", "gf", "ga"]].to_string(index=False))
print(len(games), "matches played, goals", games["gf"].sum(), "to", games["ga"].sum())
print("credits left:", client.last_credits_remaining)

Output

      date venue_side opponent  gf  ga
2026-08-23          A      NEW   2   2
2026-08-29          H      NFO   2   2
2026-09-04          A      IPS   2   0
2026-09-12          H      FUL   0   0
2026-09-20          A      BOU   1   0
2026-10-11          H      MNC   0   3
2026-10-17          A      BRE   2   1
2026-10-25          H      BHA   2   0
2026-11-01          H      ARS   0   1
2026-11-08          A      CRY   3   1
2026-11-22          H      MAN   4   0
2026-11-29          A      EVE   1   1
2026-12-02          H      SUN   2   1
13 matches played, goals 21 to 12
credits left: 13886

Liverpool has played 13 league matches, seven at home, with 21 goals for and 12 against. Those scores include own goals. Every one is a 90-minute league match, so a figure per match is also a figure per 90 minutes. A club in a cup or with extra time needs minutes, not a match count.

3. Pull every shot, with x, y, xG and outcome

There are two routes to the shots. get_events returns one match at a time: every event in order, shots with their position, outcome and xG, for both clubs. It costs 10 credits a match, so a club's 13 matches would cost 130. get_shot_map returns a whole season of one club's shots in one call, and with against=True the shots it conceded. It costs 10 credits a call, so both sides cost 20.

The rows are the same. We checked by pulling Liverpool's 2 December match against Sunderland both ways: get_events with kind="shots" and the two shot maps each gave 37 shots and 3.826 xG, and every event_id in the shot map is the seq of the matching event. That check cost 10 credits and is not part of the script below. Use get_events when you need the other events or the order of play within one match, and get_shot_map for a season of shots.

Each shot has x (distance from the goal line as a share of half the pitch), y (across the pitch, 0.5 is the centre), end_x and end_y, outcome (goal, saved, blocked, missed or woodwork), body_part, penalty, zone, xg and xg_point_in_time, our xG fitted only on earlier seasons so a backtest never sees the season it tests.

import pandas as pd
from strikerapi import Client, to_dataframe

client = Client()
TEAM, SEASON = "LIV", 2026

made = client.get_shot_map(team=TEAM, season=SEASON)
conceded = client.get_shot_map(team=TEAM, season=SEASON, against=True)
for_shots = to_dataframe(made, key="shots")
against_shots = to_dataframe(conceded, key="shots")
for_shots.to_csv("liverpool_shots_for.csv", index=False)
against_shots.to_csv("liverpool_shots_against.csv", index=False)

print("for:     ", made["totals"])
print("against: ", conceded["totals"])
cols = ["game_id", "minute", "player", "outcome", "body_part", "xg", "x", "y"]
print(for_shots[cols].head(5).to_string(index=False))
print(for_shots["outcome"].value_counts().to_dict())
print("matches covered:", for_shots["game_id"].nunique(), "for,", against_shots["game_id"].nunique(), "against")
print("credits left:", client.last_credits_remaining)

Output

for:      {'shots': 236, 'located': 236, 'goals': 20, 'on_target': 66, 'xg': 24.63, 'xg_per_shot': 0.104, 'xg_point_in_time': 22.91}
against:  {'shots': 163, 'located': 163, 'goals': 11, 'on_target': 42, 'xg': 16.71, 'xg_per_shot': 0.103, 'xg_point_in_time': 15.92}
  game_id  minute          player outcome  body_part    xg     x     y
401879219       5      Trey Nyoni  missed right_foot 0.045 0.468 0.444
401879219       8    Víctor Muñoz  missed  left_foot 0.070 0.196 0.654
401879219       9   Florian Wirtz    goal right_foot 0.197 0.150 0.636
401879219      16 Virgil van Dijk   saved     header 0.066 0.102 0.378
401879219      16      Trey Nyoni  missed right_foot 0.043 0.418 0.684
{'blocked': 85, 'missed': 83, 'saved': 46, 'goal': 20, 'woodwork': 2}
matches covered: 13 for, 13 against
credits left: 13866

Liverpool took 236 shots worth 24.63 xG and scored 20 goals. It conceded 163 shots worth 16.71 xG and 11 goals (the 163 shots add to 16.72 here because each shot's xG is rounded). The shot rows have 20 and 11 goals against scores of 21 and 12 because an own goal has no shot. Both shot maps cover all 13 matches.

4. Plot the shot map

The script draws the attacking half pitch in metres with the goal line at the top. Our x of 1 is about 48 metres from the goal line (0.23 of that is the 11 metre penalty spot), and y of 1 is the 68 metre width, so a shot sits at (y * 68, x * 48). Circle area is xG and goals are red. The right-hand panel plots the shots Liverpool conceded the same way, from the goal line they were shooting at. We do not state which touchline y = 0 is, so the left and right sides of the picture are not a claim about left and right feet.

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.patches import Rectangle, Arc, Circle

# Metres. x = 1 sits 48 m from the goal line in our frame (0.23 x 48 = the 11 m penalty spot); y = 1 is the 68 m width.
HALF_LENGTH, WIDTH = 48.0, 68.0
SHOWN = 36.0  # metres from the goal line shown; no shot in this season is farther out


def draw_half_pitch(ax):
    """The attacking half, goal line along the top. Our x runs down the page, our y across it."""
    ax.plot([0, 0, WIDTH, WIDTH], [SHOWN, 0, 0, SHOWN], lw=1.2, c="#444")  # touchlines and goal line, cut where the view ends
    ax.add_patch(Rectangle((WIDTH / 2 - 20.16, 0), 40.32, 16.5, fill=False, lw=1.2, ec="#444"))  # penalty area
    ax.add_patch(Rectangle((WIDTH / 2 - 9.16, 0), 18.32, 5.5, fill=False, lw=1.2, ec="#444"))  # six-yard box
    ax.add_patch(Rectangle((WIDTH / 2 - 3.66, -1.5), 7.32, 1.5, fill=False, lw=1.2, ec="#444"))  # goal
    ax.add_patch(Circle((WIDTH / 2, 11), 0.35, color="#444"))  # penalty spot
    ax.add_patch(Arc((WIDTH / 2, 11), 18.3, 18.3, theta1=37, theta2=143, lw=1.2, ec="#444"))  # the D
    ax.set_xlim(-1, WIDTH + 1)
    ax.set_ylim(SHOWN, -3)  # inverted: the goal is at the top
    ax.set_aspect("equal")
    ax.axis("off")


def plot_shots(ax, shots, title):
    draw_half_pitch(ax)
    px, py = shots["y"] * WIDTH, shots["x"] * HALF_LENGTH  # y across the pitch, x down from the goal line
    goal = shots["outcome"] == "goal"
    ax.scatter(px[~goal], py[~goal], s=shots["xg"][~goal] * 900, c="#7a8ca5", alpha=0.45, lw=0)
    ax.scatter(px[goal], py[goal], s=shots["xg"][goal] * 900, c="#c8102e", ec="white", lw=0.8)
    ax.set_title(title, fontsize=11)


made = pd.read_csv("liverpool_shots_for.csv")
conceded = pd.read_csv("liverpool_shots_against.csv")
fig, axes = plt.subplots(1, 2, figsize=(10, 4.6))
plot_shots(axes[0], made, f"Liverpool shots: {len(made)}, {made['xg'].sum():.1f} xG, {(made['outcome'] == 'goal').sum()} goals")
plot_shots(axes[1], conceded, f"Shots conceded: {len(conceded)}, {conceded['xg'].sum():.1f} xG, {(conceded['outcome'] == 'goal').sum()} goals")
fig.text(0.5, 0.03, "Circle area is xG. Red circles are goals. Premier League 2026-27 through 13 matches.", ha="center", fontsize=9)
fig.tight_layout(rect=(0, 0.06, 1, 1))
fig.savefig("liverpool_shot_map.png", dpi=150)
print("saved liverpool_shot_map.png")
print("x from", made["x"].min(), "to", made["x"].max(), "; y from", made["y"].min(), "to", made["y"].max())

Output

saved liverpool_shot_map.png
x from 0.024 to 0.694 ; y from 0.172 to 0.75
Two half-pitch shot maps for Liverpool in 2026-27. Left: 236 shots taken, 24.6 xG, 20 goals, mostly inside the penalty area. Right: 163 shots conceded, 16.7 xG, 11 goals.
The image the script saves. Liverpool's 236 shots and the 163 it conceded, Premier League 2026-27, through 13 matches.

Most of the weight sits in the penalty area, where the large circles are close to goal and central. Liverpool's 20 goals came from 236 shots, one every 11.8 shots, and the 163 shots it conceded are fewer and carry less xG per match.

5. Work out xG for and against per 90, and goals against xG per player

The team figures divide the totals by the 13 matches. The player table groups the club's own shots by player and sets goals against xG, with the ten players with the most xG shown. Own goals are not shots, so they are not in it. A player's xG here is only the shots he took for this club in this season's matches counted so far.

import pandas as pd

matches = pd.read_csv("liverpool_matches.csv", dtype={"game_id": str})
made = pd.read_csv("liverpool_shots_for.csv", dtype={"game_id": str, "player_id": str})
conceded = pd.read_csv("liverpool_shots_against.csv", dtype={"game_id": str})

# Every match here is a league match of 90 minutes (no extra time), so per 90 is per match played.
n = len(matches)
xgf, xga = made["xg"].sum(), conceded["xg"].sum()
print(f"{n} matches")
print(f"xG for     {xgf:.2f}  = {xgf / n:.2f} per 90   goals {int((made['outcome'] == 'goal').sum())}  shots {len(made)}  ({len(made) / n:.1f} per 90)")
print(f"xG against {xga:.2f}  = {xga / n:.2f} per 90   goals {int((conceded['outcome'] == 'goal').sum())}  shots {len(conceded)}  ({len(conceded) / n:.1f} per 90)")
print(f"xG difference {xgf - xga:+.2f} = {(xgf - xga) / n:+.2f} per 90")

# Match by match: xG for and against beside the score.
per_match = matches.set_index("game_id")[["date", "venue_side", "opponent", "gf", "ga"]].copy()
per_match["xgf"] = made.groupby("game_id")["xg"].sum()
per_match["xga"] = conceded.groupby("game_id")["xg"].sum()
print(per_match.round(2).to_string(index=False))
per_match.to_csv("liverpool_xg_by_match.csv")

# Goals minus xG per player, from the shots the club took. Own goals are not shots, so they are not here.
made["goal"] = made["outcome"] == "goal"
players = made.groupby("player").agg(shots=("xg", "size"), goals=("goal", "sum"), xg=("xg", "sum"))
players["goals_minus_xg"] = players["goals"] - players["xg"]
players["xg_per_shot"] = players["xg"] / players["shots"]
top10 = players.sort_values("xg", ascending=False).head(10)
top10.to_csv("liverpool_players_top10.csv")
print(top10.round(2).to_string())
print("top ten hold", round(top10["xg"].sum() / xgf, 3), "of the club's xG")

Output

13 matches
xG for     24.63  = 1.89 per 90   goals 20  shots 236  (18.2 per 90)
xG against 16.72  = 1.29 per 90   goals 11  shots 163  (12.5 per 90)
xG difference +7.91 = +0.61 per 90
      date venue_side opponent  gf  ga  xgf  xga
2026-08-23          A      NEW   2   2 3.42 1.07
2026-08-29          H      NFO   2   2 1.61 2.18
2026-09-04          A      IPS   2   0 0.60 0.77
2026-09-12          H      FUL   0   0 1.60 0.84
2026-09-20          A      BOU   1   0 1.63 0.88
2026-10-11          H      MNC   0   3 1.35 1.09
2026-10-17          A      BRE   2   1 1.40 1.34
2026-10-25          H      BHA   2   0 0.97 1.81
2026-11-01          H      ARS   0   1 1.35 0.76
2026-11-08          A      CRY   3   1 2.77 2.83
2026-11-22          H      MAN   4   0 3.75 0.47
2026-11-29          A      EVE   1   1 1.58 1.45
2026-12-02          H      SUN   2   1 2.60 1.22
                     shots  goals    xg  goals_minus_xg  xg_per_shot
player                                                              
Alexander Isak          35      7  6.11            0.89         0.17
Florian Wirtz           31      3  3.68           -0.68         0.12
Bradley Barcola         20      1  2.50           -1.50         0.13
Dominik Szoboszlai      29      3  2.24            0.76         0.08
Alexis Mac Allister     24      1  1.55           -0.55         0.06
Víctor Muñoz            17      3  1.41            1.59         0.08
Jérémy Jacquet           7      0  1.24           -1.24         0.18
Ronald Araujo            8      0  1.19           -1.19         0.15
Cody Gakpo              17      1  1.18           -0.18         0.07
Virgil van Dijk         11      0  1.00           -1.00         0.09
top ten hold 0.897 of the club's xG

Liverpool created 1.89 xG per 90 and allowed 1.29, a difference of +0.61 per 90, from 18.2 shots for and 12.5 against per 90. Goals went the other way in some matches: 0-3 at home to Manchester City from 1.35 xG for and 1.09 against, and 4-0 against Manchester United from 3.75 and 0.47. Alexander Isak led the club with 6.11 xG and 7 goals, 0.89 above. Víctor Muñoz had the largest gap, 3 goals from 1.41 xG (+1.59), and Bradley Barcola the largest shortfall, 1 goal from 2.50 xG (-1.50). With 20 goals in all, these gaps are a few goals, which is well within what finishing luck produces over 13 matches, so read them as a prompt to look, not a verdict.

6. Compare the club's xG with its table position

get_standings gives the table. get_team_stats gives every club's per-match xG for and against in one call, so Liverpool can be placed among all 20 without pulling 19 more shot maps. The script joins the two, ranks clubs on xG difference per match, and prints how far each club's table position is from that rank, then the rank correlation of the table with xG difference and with goal difference.

import pandas as pd
from strikerapi import Client, to_dataframe

client = Client()
TEAM, SEASON = "LIV", 2026

table = to_dataframe(client.get_standings(season=SEASON), key="standings")
stats = to_dataframe(client.get_team_stats(season=SEASON), key="teams")  # every club's per-match xG for and against

clubs = table[["rank", "abbrev", "display_name", "played", "points", "goal_diff"]].merge(
    stats[["abbrev", "xg_for", "xg_against"]], on="abbrev"
)
clubs["xg_diff_pm"] = clubs["xg_for"] - clubs["xg_against"]
clubs["points_pm"] = clubs["points"] / clubs["played"]
clubs["xg_rank"] = clubs["xg_diff_pm"].rank(ascending=False, method="min").astype(int)
clubs["rank_gap"] = clubs["rank"] - clubs["xg_rank"]  # positive: the table sits below the xG rank
clubs.to_csv("premier_league_2026_xg_vs_table.csv", index=False)

cols = ["rank", "display_name", "points", "goal_diff", "xg_for", "xg_against", "xg_diff_pm", "xg_rank", "rank_gap"]
print(clubs[cols].round(2).to_string(index=False))
print("Spearman, table rank vs xG-difference rank:", round(clubs["rank"].corr(clubs["xg_rank"], method="spearman"), 2))
print("Spearman, table rank vs goal-difference rank:", round(clubs["rank"].corr(clubs["goal_diff"].rank(ascending=False), method="spearman"), 2))
print("credits left:", client.last_credits_remaining)

Output

 rank           display_name  points  goal_diff  xg_for  xg_against  xg_diff_pm  xg_rank  rank_gap
    1                Arsenal      30         10    1.82        1.08        0.74        1         0
    2        Manchester City      26         10    1.72        1.07        0.65        2         0
    3              Liverpool      25          9    1.89        1.29        0.60        4        -1
    4 Brighton & Hove Albion      23         16    2.01        1.39        0.62        3         1
    5        AFC Bournemouth      22          5    1.57        1.39        0.18        8        -3
    6              Brentford      21         13    1.57        1.64       -0.07       10        -4
    7           Leeds United      20          6    1.52        1.17        0.35        5         2
    8      Tottenham Hotspur      19          3    1.47        1.17        0.30        7         1
    9                Chelsea      19          0    1.37        1.52       -0.15       12        -3
   10       Newcastle United      19         -1    1.31        1.74       -0.43       17        -7
   11              Hull City      18          3    1.15        1.41       -0.26       16        -5
   12            Aston Villa      18         -2    1.55        1.75       -0.20       14        -2
   13                Everton      17         -3    1.41        1.66       -0.25       15        -2
   14          Coventry City      15         -9    1.10        1.76       -0.66       18        -4
   15      Nottingham Forest      13         -5    1.62        1.27        0.35        5        10
   16                 Fulham      12         -3    1.50        1.37        0.13        9         7
   17           Ipswich Town      12         -9    1.10        1.85       -0.75       19        -2
   18             Sunderland       9        -12    1.35        1.51       -0.16       13         5
   19      Manchester United       8        -14    1.69        1.80       -0.11       11         8
   20         Crystal Palace       7        -17    1.35        2.22       -0.87       20         0
Spearman, table rank vs xG-difference rank: 0.72
Spearman, table rank vs goal-difference rank: 0.95
credits left: 13859
Points per match and xG difference per match, Premier League 2026-27
  • Points per match
  • xG difference per match
-1.000.001.002.003.00Club, in table orderPer matchPoints per match, ARS: 2.31xG difference per match, ARS: 0.74ARSPoints per match, MNC: 2.00xG difference per match, MNC: 0.65Points per match, LIV: 1.92xG difference per match, LIV: 0.60LIVPoints per match, BHA: 1.77xG difference per match, BHA: 0.62Points per match, BOU: 1.69xG difference per match, BOU: 0.18BOUPoints per match, BRE: 1.62xG difference per match, BRE: -0.07Points per match, LEE: 1.54xG difference per match, LEE: 0.35LEEPoints per match, TOT: 1.46xG difference per match, TOT: 0.30Points per match, CHE: 1.46xG difference per match, CHE: -0.15CHEPoints per match, NEW: 1.46xG difference per match, NEW: -0.43Points per match, HUL: 1.38xG difference per match, HUL: -0.26HULPoints per match, AVL: 1.38xG difference per match, AVL: -0.20Points per match, EVE: 1.31xG difference per match, EVE: -0.25EVEPoints per match, COV: 1.15xG difference per match, COV: -0.66Points per match, NFO: 1.00xG difference per match, NFO: 0.35NFOPoints per match, FUL: 0.92xG difference per match, FUL: 0.13Points per match, IPS: 0.92xG difference per match, IPS: -0.75IPSPoints per match, SUN: 0.69xG difference per match, SUN: -0.16Points per match, MAN: 0.62xG difference per match, MAN: -0.11MANPoints per match, CRY: 0.54xG difference per match, CRY: -0.87

From the table above, clubs in table order after 13 matches each. xG difference is xG for minus xG against per match, ours from located shots.

Liverpool is third in the table on 25 points and fourth on xG difference (+0.60 per match), one place apart. Arsenal, Manchester City and Crystal Palace sit where their xG rank says (first, second and last). Some are far apart: Nottingham Forest is 15th with the fifth-best xG difference, and Newcastle United is 10th with the 17th. The table follows goal difference more closely (rank correlation 0.95) than xG difference (0.72). That is expected after 13 matches: the table counts goals, which carry finishing and goalkeeping luck that xG leaves out, and a third of a season is too short for the two to converge.

7. What the xG model sees and what it does not

Our xG is a location model. For each shot it takes the league's goal rate for shots from the same distance and angle, header or not, using the five seasons around the match, and it gives penalties the league's penalty conversion. Everything in the steps above follows from that.

  • It sees where the shot was taken, whether it was a header, and whether it was a penalty.
  • It does not see defenders, the goalkeeper's position, the pass before the shot, or the shooter. A tap-in after a cut-back and a crowded scramble from the same spot get the same value.
  • So a team that shoots through traffic looks as dangerous as one that shoots into space, and a striker who finishes better than average from a spot shows up as goals above xG.
  • Read it over ten matches or more. One match's xG gap is noise. Compare per-match figures to the league, as step 6 does, rather than to zero.

Change TEAM and SEASON to run the report for another club or season, and pass league="laliga", "seriea", "bundesliga" or "ligue1" to the calls to use another league. Located shots start in 2012-13 for the Premier League (partial that first season), La Liga, Serie A, the Bundesliga and Ligue 1.

Tools and credits

One full run: 29 credits.

What you can do with the data

You may store these rows, train models and analyze them, and build products that show your users what you derive. You may not redistribute the rows as a dataset or API of its own. xG is our model's estimate from where a shot was taken, not a measure of the shot's quality or of a player's skill.

Details: data timing and rights.

What to do next

Start with 500 free credits every month

No card. pip install strikerapi, REST or MCP.