Python library written on top of matplotlib library for customizable nfl charts
Project description
NFL Play Visualizer
This Python script provides tools for visualizing NFL play data on a football field. Using matplotlib
, it creates static snapshots and animated plays of NFL games based on tracking data.
Requirements
- Python 3.x
- pandas
- matplotlib
To install the dependencies:
pip install nfl_tracks
After successfully installing the nfl_tracks package, import it in the file using the code below:
# Import nfl_tracks
from nfl import visuals
Overview
The script contains three main functions:
- field: Sets up the visual representation of a football field.
- snap: Creates a static snapshot of a specific play frame.
- play_game: Animates a play, showing player movements across frames.
Individual functions are listed below.
field()
This function sets up the football field with customizable features, such as yard numbers, touchdown markings, and a highlighted 50-yard line.
visuals.field(yard_numbers, touchdown_markings, fifty_yard, fig_size)
Parameters:
- yard_numbers (bool): Whether to display yard numbers. Default is True.
- touchdown_markings (bool): Whether to display touchdown markings. Default is True.
- fifty_yard (bool): Whether to highlight the fifty-yard line. Default is False.
- fig_size (tuple): The size of the figure in inches. Default is (12, 6.33).
Returns:
- fig (matplotlib.figure.Figure): The figure object containing the field.
- ax (matplotlib.axes._subplots.AxesSubplot): The axis object representing the field.
Example Usage:
fig, ax = visuals.field(yard_numbers=True, touchdown_markings=True)
snap()
Creates a static snapshot of a specific frame in a play. The snapshot includes player positions and can be customized with field features.
snap(data, gameId, playId, frameId, yard_numbers, touchdown_markings, fifty_yard, fig_size)
Parameters:
- data (pd.DataFrame): The DataFrame containing play data.
- gameId (int): The unique ID of the game.
- playId (int): The unique ID of the play.
- frameId (int): The frame ID of the play.
- yard_numbers (bool): Whether to display yard numbers. Default is True.
- touchdown_markings (bool): Whether to display touchdown markings. Default is True.
- fifty_yard (bool): Whether to highlight the fifty-yard line. Default is False.
- fig_size (tuple): The size of the figure in inches. Default is (12, 6.33).
Returns:
- fig (matplotlib.figure.Figure): The figure object.
- ax (matplotlib.axes._subplots.AxesSubplot): The axis object.
Example Usage:
fig, ax = visuals.snap(data, gameId=2019090800, playId=75, frameId=10)
play_game()
Animates an entire play, showing player positions and movements frame by frame. The animation can be saved as a GIF.
play_game(data, gameId, playId, yard_numbers, touchdown_markings, fifty_yard, fig_size, save, loop, **kwargs)
Parameters:
- data (pd.DataFrame): The DataFrame containing play data.
- gameId (int): The unique ID of the game.
- playId (int): The unique ID of the play.
- yard_numbers (bool): Whether to display yard numbers. Default is True.
- touchdown_markings (bool): Whether to display touchdown markings. Default is True.
- fifty_yard (bool): Whether to highlight the fifty-yard line. Default is False.
- fig_size (tuple): The size of the figure in inches. Default is (12, 6.33).
- save (bool): Whether to save the animation as a GIF. Default is False.
- loop (bool): Whether to loop the animation. Default is False.
- **kwargs: Additional keyword arguments for save_params in case saving as a GIF, such as fps and bitrate.
Returns:
- fig (matplotlib.figure.Figure): The figure object.
- ax (matplotlib.axes._subplots.AxesSubplot): The axis object.
- ani (matplotlib.animation.FuncAnimation): The animation object.
Example Usage:
fig, ax, ani = visuals.play_game(data, gameId=2019090800, playId=75, save=True, loop=True)
Example of Full Usage:
import pandas as pd
from nfl import visuals
# Load your data into a pandas DataFrame
data = pd.read_csv("week_1.csv")
# Create a field visualization
fig, ax = visuals.field(yard_numbers=True, touchdown_markings=True, fifty_yard=False, fig_size=(12, 6.33))
# Snap a specific frame of a play
fig, ax = visuals.snap(data, gameId=2019090800, playId=75, frameId=10, yard_numbers=True, touchdown_markings=True, fifty_yard=False, fig_size=(12, 6.33))
# Animate a full play and save as GIF
fig, ax, ani = visuals.play_game(data, gameId=2019090800, playId=75, yard_numbers=True, touchdown_markings=True, fifty_yard=False, fig_size=(12, 6.33), save=True, loop=False)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nfl_tracks-1.2.0.tar.gz
.
File metadata
- Download URL: nfl_tracks-1.2.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b911d19ff0256e3bb5bf7f5a1a16d5311fc5b7b53da81963195fd9ed08e760a |
|
MD5 | 224fbc5dad2fe0432c08a2d04932cbce |
|
BLAKE2b-256 | e5f9acd64e837d5b36395fd71be673a4b6bc3774c5f227405cfd2521a212951d |
File details
Details for the file nfl_tracks-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: nfl_tracks-1.2.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cda89317f50b7da38c2cf6c7bbfa8d921e6aaae5afba19c374987f95e9d5784 |
|
MD5 | c18656f9f43da065f25d334f2e7b3206 |
|
BLAKE2b-256 | 2088873d314742dcc1d86df165bbcbabe353515e010db385d37ab062ec47c23c |