Skip to content

jbf302/nflplotpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

nflplotpy

Python NFL Visualization Package - Complete nflplotR Equivalent

Python 3.8+ License: MIT

nflplotpy is a comprehensive Python visualization package for NFL data analysis, providing complete feature parity with R's popular nflplotR package. Built for the NFL analytics community, it seamlessly integrates with matplotlib, plotly, seaborn, and pandas to create stunning NFL-themed visualizations.

Inspired by and building upon the amazing work of the nflverse ecosystem and nflplotR package.

πŸš€ Quick Start

pip install nflplotpy
import nflplotpy as nflplot
import matplotlib.pyplot as plt
import pandas as pd

# Create a simple team performance scatter plot
fig, ax = plt.subplots(figsize=(12, 8))

# Add team logos at coordinates
nflplot.add_nfl_logo(ax, 'KC', x=0.5, y=0.5, width=0.1)
nflplot.add_nfl_logo(ax, 'BUF', x=0.3, y=0.7, width=0.1)

# Apply NFL theme
nflplot.apply_nfl_theme(ax, team='KC')
plt.show()

πŸ–ΌοΈ Gallery & Examples

Team Performance Analysis with Real NFL Data

All Teams EPA Analysis
All Teams EPA

Division Breakdown
Division Breakdown

Examples using real 2024 NFL Expected Points Added (EPA) data with team logos

πŸ“š Comprehensive Examples Available

Check out our examples directory for detailed code and documentation:

➀ View Full Examples Documentation for detailed tutorials and customization guides.

✨ Core Features

🎨 Team Colors & Branding

# Get team colors
nflplot.get_team_colors('KC', 'primary')  # '#e31837'
nflplot.get_team_colors(['KC', 'BUF', 'GB'])  # Multiple teams

# Create color palettes
palette = nflplot.NFLColorPalette()
afc_colors = palette.create_conference_palette('AFC')
gradient = palette.create_gradient('KC', 'SF', n_colors=10)

🏈 NFL Elements

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# Add team logos
nflplot.add_nfl_logo(ax, 'KC', x=0.5, y=0.5, width=0.1)

# πŸ†• Add team wordmarks  
nflplot.add_team_wordmark(ax, 'KC', x=0.3, y=0.8, width=0.12)

# πŸ†• Add player headshots
nflplot.add_player_headshot(ax, 'Patrick Mahomes', x=0.7, y=0.2, width=0.1)

# Add reference lines
nflplot.add_median_lines(ax, data, axis='both')

# Apply NFL theme
nflplot.apply_nfl_theme(ax, team='KC', style='default')

πŸ“Š High-Level Plotting

# Team performance scatter plot
fig = nflplot.plot_team_stats(
    data, x='offensive_epa', y='defensive_epa',
    show_logos=True, add_reference_lines=True
)

# Player comparison radar chart
fig = nflplot.plot_player_comparison(
    player_data, players=['Josh Allen', 'Patrick Mahomes'],
    metrics=['passing_yards', 'passing_tds', 'qbr'],
    plot_type='radar'
)

πŸ“‹ NFL Tables

# Style pandas DataFrames with team logos
styled = nflplot.style_with_logos(df, 'team')
styled.to_html('nfl_table.html')

# πŸ†• Add team wordmarks to tables
styled_wm = nflplot.style_with_wordmarks(df, 'team', wordmark_height=25)

# πŸ†• Add player headshots to tables  
styled_hs = nflplot.style_with_headshots(
    player_df, 'player', id_type='name', headshot_height=40
)

# Comprehensive NFL-themed tables
table = nflplot.create_nfl_table(
    standings_df, 
    team_column='team',
    title='2024 NFL Standings'
)
table.save_html('standings.html')

πŸ” Plot Preview

# Preview plots with specified dimensions
nflplot.nfl_preview(fig, width=12, height=8, dpi=150)

# Quick preview with presets
nflplot.preview_with_dimensions(fig, 'presentation')  # 16:9 format

🏷️ Advanced Elements

# Add logos to axis labels
nflplot.set_xlabel_with_logos(ax, ['KC', 'BUF', 'NE', 'NYJ'])

# Add logo watermarks
nflplot.add_logo_watermark(ax, 'KC', position='bottom_right')

# Create team comparison layouts
left_ax, right_ax = nflplot.create_team_comparison_axes(fig, 'KC', 'BUF')

API Reference

Main Functions

Function Description nflplotR Equivalent
get_team_colors() Get NFL team colors team_colors
add_nfl_logo() Add team logo to plot geom_nfl_logos()
add_median_lines() Add reference lines geom_median_lines()
style_with_logos() Add logos to tables gt_nfl_logos()
nfl_preview() Preview plots ggpreview()
nfl_sitrep() System information nflverse_sitrep
plot_team_stats() High-level team plots Custom implementation
team_factor() Ordered team factors nfl_team_factor()
team_tiers() Group teams by tiers nfl_team_tiers()

Classes

  • NFLAssetManager: Manages logo caching and asset downloads
  • NFLColorPalette: Advanced color palette management
  • NFLTableStyler: Pandas DataFrame styling with NFL elements
  • AssetURLManager: Comprehensive URL management for all NFL assets

Visualization Backends

  • Matplotlib: nflplotpy.matplotlib.*
  • Plotly: nflplotpy.plotly.*
  • Seaborn: nflplotpy.seaborn.*

πŸ“¦ Installation Options

# Basic installation
pip install nflplotpy

# With plotly support
pip install nflplotpy[plotly]

# With seaborn support  
pip install nflplotpy[seaborn]

# Complete installation with all backends
pip install nflplotpy[all]

# Development installation
pip install nflplotpy[dev]

πŸ—οΈ Package Structure

nflplotpy/
β”œβ”€β”€ core/           # Core functionality (colors, logos, utilities, URLs)
β”œβ”€β”€ matplotlib/     # Matplotlib integration (artists, scales, preview, elements)
β”œβ”€β”€ plotly/         # Plotly integration  
β”œβ”€β”€ seaborn/        # Seaborn integration
β”œβ”€β”€ pandas/         # Pandas table styling integration
β”œβ”€β”€ data/           # Team metadata
β”œβ”€β”€ examples/       # Usage examples and tutorials
└── tests/          # Comprehensive test suite

🀝 Contributing

nflplotpy welcomes contributions! Here's how you can help:

  1. Report Issues: Found a bug? Open an issue
  2. Feature Requests: Have an idea? We'd love to hear it!
  3. Code Contributions: Fork, develop, and submit a pull request
  4. Documentation: Help improve our docs and examples

Development Setup

git clone https://github.com/joelfeinberg/nflplotpy.git
cd nflplotpy
pip install -e .[dev]
pytest tests/

🌟 Community & Support

⚑ Requirements

  • Python: 3.8+
  • Core Dependencies: matplotlib, pandas, numpy, pillow, requests
  • Optional: plotly (5.0+), seaborn (0.11+)
  • Supports: CPython, PyPy

πŸ“„ License

MIT License - see LICENSE file for details.

This package is inspired by and builds upon the amazing work of the nflverse ecosystem and nflplotR package.

πŸ™ Acknowledgments

  • nflplotR: Original R package that inspired this work
  • nflverse: Amazing NFL data ecosystem and community
  • NFL Analytics Community: For continuous feedback and support

Built for the NFL analytics community 🏈

Compatible with nfl_data_py, nflfastR, and other nflverse tools.

About

Python NFL Visualization Package

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages