Skip to main content

No project description provided

Project description

mplhockey logo

mplhockey is a Python library for plotting hockey rink charts in Matplotlib.

It provides accurate, publication-ready rink geometries across multiple leagues, with flexible unit handling, rotation, and zone-based rendering. The library is intentionally lightweight and designed to integrate cleanly into standard Matplotlib workflows.


Installation

Use the package manager pip to install mplhockey.

pip install mplhockey

Alternatively, you can install it in development mode directly from GitHub:

git clone https://github.com/mlsedigital/mplhockey.git
cd mplhockey
git checkout develop && git pull
pip install -e .

If you are using uv, you can add it directly to your project:

uv add mplhockey

Quick start

Create and draw a standard NHL rink:

from mplhockey import NHLRink

rink = NHLRink()
rink.draw()

sample rink

All rinks expose the units they are currently parameterized in:

rink.units

You can control the units directly when constructing the rink:

rink = NHLRink(units="m")
rink.draw()

Or override the units at draw time:

rink.draw(units="mm")

Other Themes

By default we show the light theme, but there is also a dark theme for each rink which is accessible on the constructor.

from mplhockey import NHLRink
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

rink = NHLRink(theme="dark")
rink.draw(ax=ax)

ax.set_axis_off()

# Make EVERYTHING dark
ax.set_facecolor("#202020")
fig.patch.set_facecolor("#202020")
plt.show()

dark rink

Custom Themes

Default schemes are housed in a schemes.yaml file which lays out colours each of the elements. Optionally, when the rink object is instantiated, you can pass in a dictionary that explictly defines those items. For example:

from mplhockey import KHLRink

my_theme = {
    "ice": "#F4F8FB",          # very light icy white-blue
    "outline": "#8A9199",      # cool neutral gray (softer than pure gray)
    "red": "#C83E3E",          # slightly muted hockey red (less neon)
    "blue": "#2C6FB7",         # deep rink blue (good contrast on ice)
    "crease": "#A6D6E0",       # soft cyan / goalie-crease blue
    "net": "#EDEDED",          # off-white (avoids pure white glare)
    "penalty_box": "#E6E6E6",  # subtle light gray
    "bench": "#DADADA",        # slightly darker than penalty box
}

rink = KHLRink(
    theme = my_theme,
    units = 'm',
)

rink.draw()

Will produce something like:

custom KHL


Rotation and display ranges

Rinks can be rotated by passing a rotation argument (in degrees) either to the constructor or the draw method.

You can also render only a subset of the rink, such as a single zone:

from mplhockey import NHLRink

rink = NHLRink()
rink.draw(rotation=90, display_range="ozone")

roated rink

This is particularly useful for producing attacking-direction–consistent visualizations or focused zone-level analyses.

The default themes are great for showing animations of a hockey game or showing event locations from other data providers. However, for heatgrids they tend not to show up too well, so we've included two other themes over-dark and over-light which make the colour of the rink-markings uniform.

roated heatgrid rink


Coordinate system

All rinks in mplhockey are defined in a right-handed Cartesian coordinate system centered at center ice:

  • The origin (0, 0) is at center ice
  • The x-axis runs along the length of the rink
  • The y-axis runs across the width of the rink

This coordinate system makes it straightforward to overlay spatial data such as shot locations, tracking data, or model outputs, while preserving geometric correctness across leagues and unit systems.


Customization and Matplotlib integration

Rinks are rendered as standard Matplotlib artists. This means:

  • You can freely overlay scatter plots, lines, contours, or heatmaps
  • Axis limits, aspect ratios, and styling behave exactly as expected
  • Figures can be exported to PNG, SVG, PDF, or any Matplotlib-supported format

The goal is to provide a clean geometric foundation without constraining downstream visualization choices.


Supported rinks

mplhockey currently supports the following rink types:

  • NHLRink (National Hockey League Rink)
  • NCAARink (National Collegiate Athletic Association Rink)
  • IIHFRink (International Ice Hockey Federation Rink)
  • KHLRink (Kontinental Hockey League Rink)
  • PWHLRink (Standard PWHL Rink; same as NHL Rink)
  • NRLRink (Standard Ringette Rink)

All rink classes accept an optional units argument, allowing them to be reparameterized consistently in different unit systems.

The design is intentionally extensible, making it straightforward to add new leagues, historical dimensions, or custom surfaces.


Design philosophy

mplhockey is deliberately focused on geometry and rendering only.

It does not:

  • Fetch or manage hockey data
  • Impose a data model for events or players
  • Replace general-purpose plotting libraries

Instead, it aims to be a robust, composable building block for analysis, research, and visualization pipelines.

Users familiar with mplsoccer should find the mental model immediately familiar, adapted to the conventions and geometry of hockey.


License

mplhockey is released under the MIT License.

You are free to use, modify, and redistribute this software for both commercial and non-commercial purposes. See the LICENSE file for full details.


Acknowledgements

mplhockey is inspired by the design philosophy and success of mplsoccer and mplbasketball, adapting similar ideas to the unique geometric and visualization needs of hockey.

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

mplhockey-1.0.0.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mplhockey-1.0.0-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

File details

Details for the file mplhockey-1.0.0.tar.gz.

File metadata

  • Download URL: mplhockey-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mplhockey-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5dba51f46461186d8228b8f151c53818504ea7fb6935aa32becc5206090d8574
MD5 a1926150ab71374a55fef78db250a9bb
BLAKE2b-256 fa0f4f0e590f73b2422b6c2838dc2a6de137465039b4c901b11bcc1c762aa097

See more details on using hashes here.

Provenance

The following attestation bundles were made for mplhockey-1.0.0.tar.gz:

Publisher: publish-pypi.yml on mlsedigital/mplhockey

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mplhockey-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mplhockey-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 39.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mplhockey-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 142dff2472cc186131e4914628ca3b1e0acf33b5a86e4a7d52750ad509228293
MD5 d85b8e24e8c35c743a307524ae5e7b31
BLAKE2b-256 8f007f60c02ae1c1deadf54dac4ee4a089d906f0b58728901c49a039666abd9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mplhockey-1.0.0-py3-none-any.whl:

Publisher: publish-pypi.yml on mlsedigital/mplhockey

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page