Table of Contents
sportypy for Python Sports Surfaces
sportypy
sportypy is the Python counterpart
to sportyR, also authored by Ross
Drucker. It draws scaled, rule-book-accurate representations of sports playing
surfaces with matplotlib, so your shot charts,
tracking plots, and heatmaps sit on geometry that matches the real thing.
If you live in the PyData stack — pandas, matplotlib, seaborn — sportypy
gives you the same surface fidelity that sportyR brings to ggplot2.
Installation
pip install sportypyQuick start
Every surface is a class you instantiate and draw(). Pass an existing
matplotlib Axes to layer your own data on top:
import matplotlib.pyplot as plt
from sportypy.surfaces.basketball import NBACourt
fig, ax = plt.subplots(figsize=(12, 6.5))
# Draw a regulation NBA court...
NBACourt().draw(ax=ax)
# ...then add your data
ax.scatter(shots["x"], shots["y"], c="#024F84", alpha=0.6)
plt.show()Basketball, football, hockey, baseball, soccer, tennis, volleyball, and curling surfaces are all included, with league presets selectable per surface.
Learn more
- Documentation: sportypy.sportsdataverse.org
- R sibling:
sportyR