Skip to main content

nfl-tracks

nfl-tracks is a Python library built on top of Matplotlib for creating insightful and customizable visualizations of NFL player tracking data. Designed with the NFL Big Data Bowl in mind, it provides a simple interface to plot static plays, generate dynamic animations, and view detailed, context-rich breakdowns of individual plays.

Key Features

  • Standard Field Visualization: Generate a regulation NFL field with customizable markings.
  • Single Frame Plotting: Visualize player positions at any specific moment in a play.
  • Dynamic Animations: Create smooth, animated GIFs or videos of entire plays.
  • "Relay" Dashboard View: A comprehensive visualization that includes:
    • Live scoreboard with team details and win probabilities.
    • Highlighted player card with key stats (name, position, height, etc.).
    • On-field play and game context.
    • Automatic highlighting of the targeted or predicted player.
  • Kaggle Notebook Compatibility: Easily render animations directly within Kaggle notebooks.
  • Out-of-Bounds Tracking: Players and the ball are visualized even when they go outside the field of play, without distorting the field's proportions.

Installation

You can install nfl-tracks using pip:

pip install nfl_tracks

Function Overview

The core of the library is the visuals.Play class, which you initialize once for a specific play. You can then call its methods to generate different visualizations.

Initialization of a visualization object for a specific play. This is the first step before you can plot or animate anything.

  • data (pd.DataFrame): The main tracking data.
  • gameId (int): The unique identifier for the game.
  • playId (int): The identifier for the play.
  • context_data (pd.DataFrame): The supplementary data containing game and play context.
# Data Preparation
import pandas as pd
from nfl import visuals

tracking_data = pd.read_csv(f'data/train/input_2023_w02.csv')
context_data = pd.read_csv(f'data/supplementary_data.csv', dtype={25: str})

data = tracking_data[(tracking_data['game_id'] == 2023091400) & (tracking_data['play_id'] == 3438)]
play = visuals.Play(data, gameId, playId, context_data)

plot_snap

This is useful for analyzing player formations and positions at a key moment, like the snap or the moment a pass is thrown.

Standard View (relay=False)
This is the default mode. It generates a clean and simple plot of the football field with the players' positions.

# Plots frame 10 of the play on a standard field
fig, ax = play.plot_snap(frameId=10)
plt.show()

plot_snap

Relay Dashboard View (relay=True)
This mode creates a rich, informational dashboard around the field, providing deep context for the play. It includes a scoreboard, game information, and a detailed card for a highlighted player.

# Plots frame 10 using the advanced relay dashboard
fig, ax = play.plot_snap(frameId=10, relay=True)
plt.show()

plot_snap

play.animate

Generates a full animation of the play from the first frame to the last. This is the best way to see a play unfold, showing player routes and movements in real-time.

Standard Animation (relay=False)
This creates a simple, clean animation of the players moving on the field. It's great for embedding in presentations or for a quick look at the play's dynamics.

# Generates a standard animation of the play
# Use kaggle=True to display it in a notebook
standard_animation = play.animate(kaggle=True)
standard_animation

animate

Relay Dashboard Animation (relay=True)
This creates a simple, clean animation of the players moving on the field. It's great for embedding in presentations or for a quick look at the play's dynamics.

# Generates a relay dashboard animation of the play
relay_animation = play.animate(relay=True, kaggle=True)
relay_animation

animate

Additional Parameters (**kwargs) You can customize your plots and animations with these optional arguments:

  • highlight_player_id (int): Manually specify an nfl_id to highlight in the relay view. If not provided, it defaults to the player with player_to_predict=True.
  • club_colors (dict): A dictionary to override default offense/defense colors (e.g., {'Offense': '#006400', 'Defense': '#8B0000'}).
  • size (int): The marker size for players on the field.
  • speed (int): The delay between frames in milliseconds for animations (a lower number is faster).

License

This project is licensed under the MIT License - see the LICENSE file for details.


This library is ideal for visualizing football plays with clear, customizable graphics and animations. For further assistance, refer to Matplotlib's documentation or provide specific details for troubleshooting.

Metadata

Release files for nfl-tracks 1.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nfl-tracks 1.3.2
File Size Uploaded
nfl_tracks-1.3.2.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nfl-tracks 1.3.2
File Interpreter ABI Platform
nfl_tracks-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.7 kB

Release files / nfl_tracks-1.3.2.tar.gz

Download URL nfl_tracks-1.3.2.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8f331667610adaa1e07eda9f780f979cc8d6364c37776eb10a7c748edbccb5b8
BLAKE2b-256 checksum
How to use checksums
bf0caa1a46b02bdde4ab2d9333ffa28a71697b33e3a61949388998c7ef69a5df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / nfl_tracks-1.3.2-py3-none-any.whl

Download URL nfl_tracks-1.3.2-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a94ecfa1245caf344716ab8691566e6762c39763b1e747760133d8bbd3dba866
BLAKE2b-256 checksum
How to use checksums
50bddfa362ab2c7c3e7aede7563648332409bdd1cf49d5a26ffb8e89a628846c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page