Skip to main content
Version: main

team_colors

team_colors(
league: str,
teams: Any,
*,
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', 'yahoo', 'kenpom', 'torvik', 'sdvplotr', 'name', 'nhl_id', 'fox', 'cbs', 'sports247', 'on3'] = 'auto',
strict: bool = False,
) -> Any

One "#hex" (or None) per team value, in the same container the values came in.

Arguments​

NameTypeDescription
leaguestrThe SDV league key, e.g. "nfl".
teamsAnyA scalar, list/tuple, numpy array, or pandas/polars Series of team identifiers.
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', 'yahoo', 'kenpom', 'torvik', 'sdvplotr', 'name', 'nhl_id', 'fox', 'cbs', 'sports247', 'on3']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​

str | list | Series | None: The hex color for each team, None where a team does not resolve or has no color.

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 (a list or Series there is the pre-0.1 team_colors(teams, league) order), which is not "primary"/"secondary", 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.
  • UnresolvedTeamError: (a ValueError) If strict=True and a team does not resolve.

Example​

import sdvplot

sdvplot.team_colors("nfl", ["KC", "SF"]) # ['#e31837', '#aa0000']
sdvplot.team_colors("nfl", "KC", which="secondary") # '#ffb612'
sdvplot.team_colors("nhl", [1, 6, 10], id_system="nhl_id") # NHL stats ids: Devils, Bruins, Leafs

See also​