Complete API Reference for NFL Data Visualization in Python
This document provides comprehensive documentation for all functions and classes in nflplotpy, organized by functionality.
- Installation & Setup
- Core Functions
- Matplotlib Integration
- Plotly Integration
- Pandas Table Styling
- Color Management
- Asset Management
- Utility Functions
- Configuration
pip install nflplotpy# For plotly support
pip install nflplotpy[plotly]
# For seaborn integration
pip install nflplotpy[seaborn]
# For nfl_data_py integration
pip install nflplotpy[nfldata]
# Install everything
pip install nflplotpy[all]import nflplotpy as nfl
import matplotlib.pyplot as plt
import pandas as pd
# Ready to create NFL visualizations!Add a single NFL team logo to matplotlib plot.
Parameters:
ax(matplotlib.Axes): The axes to add logo toteam(str): Team abbreviation (e.g., 'KC', 'BUF')x(float): X coordinate for logo placementy(float): Y coordinate for logo placementwidth(float): Logo width in axes coordinatesalpha(float): Transparency (0-1)
Returns: AnnotationBbox object
Example:
fig, ax = plt.subplots()
nfl.add_nfl_logo(ax, 'KC', 0.5, 0.5, width=0.15)
plt.show()Add multiple NFL team logos to matplotlib plot.
Parameters:
teams(list): List of team abbreviationsx(list): X coordinates for each logoy(list): Y coordinates for each logo- Other parameters same as
add_nfl_logo()
Example:
teams = ['KC', 'BUF', 'CIN']
x_pos = [0.2, 0.5, 0.8]
y_pos = [0.3, 0.7, 0.4]
nfl.add_nfl_logos(ax, teams, x_pos, y_pos, width=0.1)Add NFL player headshots to matplotlib plot.
Parameters:
player_ids(list): Player identifiers (names, ESPN IDs, GSIS IDs)id_type(str): Type of identifier ('espn', 'gsis', 'name', 'auto')- Other parameters same as logo functions
Example:
# Using player names
players = ['Patrick Mahomes', 'Josh Allen']
x_pos = [0.3, 0.7]
y_pos = [0.5, 0.5]
nfl.add_nfl_headshots(ax, players, x_pos, y_pos, width=0.12)Add any image from URL or file path to matplotlib plot. Equivalent to nflplotR's geom_from_path().
Parameters:
path(str): URL or file path to imagex, y(float): Position coordinateswidth(float): Image widthheight(float, optional): Image height (maintains aspect ratio if None)angle(float): Rotation angle in degreescolorize(str, optional): Color overlay (hex code)alpha(float): Transparency
Example:
# Add image with rotation and colorization
nfl.add_image_from_path(ax, 'https://example.com/logo.png',
x=0.5, y=0.5, width=0.1,
angle=45, colorize='#FF0000')Create NFL team color scale mapping. Equivalent to nflplotR's scale_color_nfl().
Parameters:
data(list): List of team abbreviationscolor_type(str): 'primary', 'secondary', or 'alt'guide(bool): Whether to include legend informationalpha(float): Color transparency
Returns: (colors_dict, legend_info) tuple
Example:
teams = ['KC', 'BUF', 'NE', 'MIA']
colors, legend = nfl.scale_color_nfl(teams, color_type='primary')
# Use in scatter plot
plt.scatter(x_data, y_data, c=[colors[team] for team in teams])Color teams by conference (AFC/NFC).
Example:
colors, _ = nfl.scale_color_conference(['KC', 'SF', 'BUF', 'DAL'])
# AFC teams get one color, NFC teams get anotherColor teams by division.
Add mean reference lines with optional confidence bands.
Parameters:
data(array-like): Data for calculating meanorientation(str): 'horizontal', 'vertical', or 'both'confidence_band(bool): Add confidence interval shadingmethod(str): 'simple' or 'trend' for trend line
Add quantile reference lines.
Example:
# Add quartile lines
nfl.add_quantile_lines(ax, data, quantiles=[0.25, 0.5, 0.75])Add reference band between two values.
Create custom legend using team logos instead of color patches.
Example:
teams = ['KC', 'BUF', 'CIN']
labels = ['Kansas City Chiefs', 'Buffalo Bills', 'Cincinnati Bengals']
nfl.create_logo_legend(ax, teams, labels, loc='upper right')Create interactive plotly scatter plot with team logos and hover data.
Parameters:
df(DataFrame): Data containing team informationx_col, y_col(str): Column names for x and y axesteam_col(str): Column containing team abbreviationshover_data(list): Additional columns to show on hovershow_logos(bool): Whether to show team logos as points
Example:
df = pd.DataFrame({
'team': ['KC', 'BUF', 'CIN'],
'offense_epa': [0.15, 0.12, 0.08],
'defense_epa': [-0.10, -0.08, -0.05]
})
fig = nfl.create_interactive_team_plot(
df, 'offense_epa', 'defense_epa', 'team',
title='Team EPA Analysis',
hover_data=['wins', 'losses']
)
fig.show()Add team logo to plotly figure.
Apply NFL color scales to plotly traces.
Add team logos to DataFrame columns. Equivalent to R's gt_nfl_logos().
Example:
standings = pd.DataFrame({
'team': ['KC', 'BUF', 'CIN'],
'wins': [14, 13, 12],
'losses': [3, 4, 5]
})
# Create table with logos
styled = nfl.style_with_logos(standings, 'team')
styled.to_html('standings.html')Add player headshots to DataFrame. Equivalent to R's gt_nfl_headshots().
Example:
qb_stats = pd.DataFrame({
'player': ['Patrick Mahomes', 'Josh Allen', 'Joe Burrow'],
'team': ['KC', 'BUF', 'CIN'],
'passing_yards': [4183, 4306, 3446]
})
styled = nfl.style_with_headshots(qb_stats, 'player')Add team wordmarks to DataFrame columns.
Create comprehensive NFL-styled table with logos, colors, and professional styling.
Example:
table = nfl.create_nfl_table(
standings,
team_column='team',
logo_columns=['team'],
color_columns=['wins'],
title='2024 NFL Standings'
)
table.save_html('standings.html')For advanced customization, use the NFLTableStyler class with method chaining:
styler = nfl.NFLTableStyler(df)
table = (styler
.with_team_logos('team', logo_height=30)
.with_team_colors(['wins', 'losses'], 'team', apply_to='background')
.with_nfl_theme(alternating_rows=True)
)
table.save_html('custom_table.html')Methods:
.with_team_logos(columns, logo_height=25, replace_text=True).with_team_colors(columns, team_column, color_type='primary', apply_to='background').with_nfl_theme(alternating_rows=True, header_style='default').to_html(**kwargs)- Export to HTML string.save_html(filename, **kwargs)- Save to HTML file
Get team colors for multiple teams.
Parameters:
teams(list): Team abbreviationscolor_type(str): 'primary', 'secondary', 'alt'
Returns: List of color hex codes
Create matplotlib colormap from team colors.
Advanced color palette management class.
Methods:
.get_team_palette(team, n_colors=5)- Get color palette for team.create_gradient(team1, team2, n_colors=10)- Gradient between teams.get_division_palette(conference, division)- Colors for division teams
Manages URLs for all NFL assets.
Methods:
.get_logo_url(team)- Get team logo URL.get_wordmark_url(team)- Get team wordmark URL.get_player_headshot_urls(player_id, id_type='auto')- Get headshot URLs
Download and cache team logo as PIL Image.
Parameters:
team(str): Team abbreviationcache(bool): Whether to use local caching
Returns: PIL Image object
Get team's conference ('AFC' or 'NFC').
Get team's division ('East', 'West', 'North', 'South').
Get list of division rival teams.
Example:
rivals = nfl.get_division_rivals('KC') # ['LV', 'LAC', 'DEN']Get all teams in a conference.
Get all teams in a specific division.
Example:
afc_west = nfl.get_teams_by_division('AFC', 'West')
# Returns: ['KC', 'LV', 'LAC', 'DEN']Validate team abbreviations and suggest corrections.
Get list of all valid team abbreviations.
Display system information and package status.
nfl.nfl_sitrep()
# Shows: Python version, package versions, available features- Automatic ID type detection
- Fuzzy name matching
- Cross-reference between ESPN, GSIS, and NFL IDs
- Graceful fallbacks when external data unavailable
add_nfl_logo,add_nfl_logos,add_nfl_headshotsadd_image_from_path,create_logo_legend- Matplotlib and Plotly integration functions
scale_color_nfl,scale_color_conference,scale_color_divisionget_team_colors,create_nfl_colormap- Color palette management
add_mean_lines,add_quantile_lines,add_reference_bandadd_median_lines,add_percentile_lines
style_with_logos,style_with_headshots,style_with_wordmarkscreate_nfl_table,NFLTableStylerclass
- Conference/division functions, team validation
- Asset URL management, team information lookup
- Plotly integration, interactive plots
- Enhanced hover information, logo traces
- Element replacement, custom styling
- Image transformations, statistical analysis
Total: 63+ exported functions providing complete nflplotR parity
1. Simple Logo Scatter Plot:
fig, ax = plt.subplots()
teams = ['KC', 'BUF', 'CIN']
x, y = [1, 2, 3], [10, 15, 12]
nfl.add_nfl_logos(ax, teams, x, y, width=0.1)2. Colored by Conference:
colors, _ = nfl.scale_color_conference(teams)
plt.scatter(x, y, c=[colors[t] for t in teams])3. Professional Table:
table = nfl.create_nfl_table(df, team_column='team', title='NFL Stats')
table.save_html('report.html')4. Interactive Plot:
fig = nfl.create_interactive_team_plot(df, 'x_col', 'y_col', 'team')
fig.show()- Examples: See
examples/directory for comprehensive usage examples - Advanced Guide:
ADVANCED_FEATURES_GUIDE.mdfor complex visualizations - GitHub: nflplotpy repository for latest updates
- Issues: Report bugs and request features on GitHub
This documentation covers all 63+ functions available in nflplotpy v2.0, providing complete feature parity with R's nflplotR package plus additional Python-specific enhancements.