Analyzing Tactical Formations

Beginner 10 min read 1 views Nov 27, 2025
# Overview Analyze team formations and positioning patterns to understand tactical setups and player roles. ## Python Implementation ```python import pandas as pd import numpy as np import matplotlib.pyplot as plt from scipy.spatial import ConvexHull # Load match tracking data df = pd.read_csv('match_tracking.csv') # Calculate average positions by player formation = df.groupby('player_id')[['x_position', 'y_position']].mean() # Visualize formation plt.figure(figsize=(10, 14)) plt.scatter(formation['x_position'], formation['y_position'], s=200, c='blue', alpha=0.6) for idx, player in formation.iterrows(): plt.annotate(idx, (player['x_position'], player['y_position']), ha='center', va='center', fontsize=10, color='white') plt.xlim(0, 100) plt.ylim(0, 100) plt.title('Team Formation - Average Positions') plt.xlabel('Field Width') plt.ylabel('Field Length') plt.grid(True, alpha=0.3) plt.show() # Calculate formation compactness compactness = formation.std().mean() print(f"Formation Compactness: {compactness:.2f}") ``` ## R Implementation ```r library(ggplot2) library(dplyr) # Load tracking data tracking_data <- read.csv("match_tracking.csv") # Calculate average positions formation <- tracking_data %>% group_by(player_id) %>% summarise( avg_x = mean(x_position), avg_y = mean(y_position), .groups = "drop" ) # Visualize formation ggplot(formation, aes(x = avg_x, y = avg_y)) + geom_point(size = 8, color = "blue", alpha = 0.6) + geom_text(aes(label = player_id), color = "white", size = 3) + xlim(0, 100) + ylim(0, 100) + labs( title = "Team Formation - Average Positions", x = "Field Width", y = "Field Length" ) + theme_minimal() + theme(panel.grid = element_line(alpha = 0.3)) # Calculate formation metrics formation_width <- max(formation$avg_x) - min(formation$avg_x) formation_length <- max(formation$avg_y) - min(formation$avg_y) cat(sprintf("Formation Width: %.2f\n", formation_width)) cat(sprintf("Formation Length: %.2f\n", formation_length)) ```

Discussion

Have questions or feedback? Join our community discussion on Discord or GitHub Discussions.