Skip to main content
Version: 0.1.1

palette

palette(
league: str,
teams: Any = None,
*,
which: Literal['primary', 'secondary'] = 'primary',
season: Any = None,
id_system: Literal['auto', 'team_id', 'espn', 'espn_abbr', 'nhl', 'nflverse', 'mlbstats', 'nba_api', 'hockeytech', 'ncaa', 'pff', 'cricinfo', 'cfbd', 'bref', 'sportsipy', 'fangraphs', 'sdvplotr', 'name', 'nhl_id'] = 'auto',
strict: bool = False,
) -> dict[Any, str]

A {team: "#hex"} dict for a league, ready for seaborn, Plotly, Altair, Bokeh or PyPalettes.

Without teams the keys are canonical abbreviations, or the team_id where a team has no abbreviation or shares it with another team of the league (never guessing which team an abbreviation means). With teams the keys are the caller's own values, so they match a seaborn hue column or a Plotly color column exactly.

Arguments​

NameTypeDescription
leaguestrThe SDV league key, e.g. "nfl".
teamsAnyTeam values to key the dict by; None returns the whole league.
whichLiteral['primary', 'secondary']"primary" or "secondary".
seasonAnyOne season, or one per team, for values reused across eras.
id_systemLiteral['auto', 'team_id', 'espn', 'espn_abbr', 'nhl', 'nflverse', 'mlbstats', 'nba_api', 'hockeytech', 'ncaa', 'pff', 'cricinfo', 'cfbd', 'bref', 'sportsipy', 'fangraphs', 'sdvplotr', 'name', 'nhl_id']The id system of teams, as in resolve: "auto" tries each in order; NHL stats ids need "nhl_id".
strictboolRaise UnresolvedTeamError instead of warning when a team does not resolve.

Returns​

dict — {team: "#hex"}. Teams that do not resolve, or have no color, are left out. Without teams, a team whose abbreviation another team of the league shares is keyed by its team_id, with one SdvplotWarning naming the shared abbreviations.

Raises​

  • TypeError: If teams is not a scalar, list, tuple, numpy array, or pandas/polars Series.
  • InputError: (a ValueError) If league is not a known league key or which is not "primary"/"secondary"; and, when teams is given, if it holds "primary" or "secondary" (the slot goes in which=), id_system is unknown, or season is not a year, is outside the seasons sdvplot knows for the league, or is a list whose length does not match the teams. Without teams they are not checked.
  • UnresolvedTeamError: (a ValueError) If strict=True and a team does not resolve.

Example​

import sdvplot

sdvplot.palette("nfl", teams=["KC", "SF"]) # {'KC': '#e31837', 'SF': '#aa0000'}

See also​