This repository contains a comprehensive project for analyzing and visualizing football (soccer) event data. By leveraging StatsBomb JSON event files, the project extracts detailed information on shots, passing networks, defensive actions, and player movements. The code generates a variety of visualizations—from heatmaps and movement trajectories to network graphs and zone distributions—to provide deep insights into team tactics and individual player performance.
This project processes football match event data to extract key tactical and performance insights. The analyses include:
- Shot Analysis: Visualizes shot outcomes, expected goals (xG) heatmaps, shot success rates by field zone, and shot technique comparisons.
- Passing Network & Defensive Analysis: Builds passing networks to identify key playmakers, analyzes defensive actions (e.g., pressures, interceptions, blocks), and maps pressing intensity.
- Player Movement and Positioning: Creates heatmaps of player positions, analyzes movement directions with arrows, and examines under-pressure actions and team interaction patterns.
Each module overlays its visualizations on a realistically drawn soccer field, enhancing the interpretability and aesthetic quality of the outputs.
https://www.kaggle.com/datasets/ekrembayar/statsbomb-football-event-data The event data is sourced from StatsBomb JSON files. These files contain detailed event-level information from football matches (e.g., match ID "7530"). The data includes information on player actions, locations on the pitch, event types (e.g., Shot, Pass, Pressure), and additional metadata (e.g., shot outcome, expected goals).
The project is organized into several key modules:
- Field Drawing:
Thedraw_soccer_field(ax)
function uses Matplotlib patches to draw a soccer field with proper dimensions, including penalty areas, goal areas, and the center circle. - Shot Extraction & Heatmap:
Functions such asget_player_events()
,get_location_data()
, andplot_basic_heatmap()
extract shot locations for a given player and generate a heatmap (with Gaussian smoothing) to show shooting intensity. - Advanced Shot Analysis:
Additional functions (e.g.,plot_movement_analysis()
,plot_pressure_analysis()
, andplot_team_interaction()
) overlay movement arrows, pressure points, and passing trajectories to analyze shot outcomes and team interactions. - Composite Visualization:
Theplot_advanced_analysis()
function composes multiple subplots into a grid layout to provide a detailed analysis of an individual player's actions.
- Passing Network:
(See previous modules for passing network analysis.) The project includes functions to filter pass events and build a directed graph of player interactions using NetworkX. - Defensive Analysis:
The moduleanalyze_defensive_actions()
extracts defensive events (e.g., Pressure, Interception, Block) for a team, aggregates them by player, and computes summary statistics.- The
visualize_pressure_map()
function creates a heatmap of pressing locations. - The
analyze_team_pressing()
function evaluates pressing triggers (such as presses after losing possession or near the sidelines).
- The
- Movement & Heatmap Generation:
Functions likeget_player_events()
andget_location_data()
retrieve location data for a specified player.plot_basic_heatmap()
visualizes the density of player actions as a heatmap.
- Trajectory Analysis:
plot_movement_analysis()
draws arrows between sequential locations to indicate movement direction and speed. - Pressure & Interaction:
plot_pressure_analysis()
identifies events where the player was under pressure, whileplot_team_interaction()
displays pass trajectories between the player and teammates. - Composite Player Analysis:
Theanalyze_player()
function retrieves basic player information (team and position) and combines all the visualizations into a comprehensive analysis figure.
*Required libraries include:*
- pandas
- numpy
- matplotlib
- seaborn
- scipy
- networkx
-
Data Preparation:
Place your StatsBomb JSON event files in the designated data folder (e.g.,/kaggle/input/
). -
Running Analyses:
The project scripts are modular. For example, to analyze a specific player's movement and positioning, update theplayer_name
variable in the analysis script and run:The script will load the match event data (e.g., from
7530.json
), generate visualizations for player heatmaps, movement directions, pressure actions, and team interactions, and display the resulting figures. -
Customizing Analyses:
You can modify parameters such as bin sizes for heatmaps, color schemes, and grid layout settings directly within the functions.
Contributions, suggestions, and improvements are welcome! Please fork the repository and submit a pull request with your changes. For major changes, please open an issue first to discuss what you would like to modify.
This project is licensed under the MIT License. See the LICENSE file for more details.
For any questions or feedback, please contact: [email protected]