Skip to main content
Version: main

sdvplot.plottable

plottable columns of team logos, wordmarks and player headshots.

NameWhat it is
headshot_columnA plottable column that shows each row's player as a headshot.
logo_columnA plottable column that shows each row's team as its logo (or wordmark).
plottable_sdv_themeThe plottable.Table keywords that style a table like one of the 122 surveyed themes.

headshot_column​

headshot_column(
name: str,
*,
league: str,
id_system: str = 'espn',
**column_definition_kwargs: Any,
) -> plottable.column_def.ColumnDefinition

A plottable column that shows each row's player as a headshot.

Arguments​

NameTypeDescription
namestrThe data column holding the player ids.
leaguestrThe SDV league key, e.g. "nfl".
id_systemstr"espn" (ESPN athlete ids), "gsis" (NFL) or "league" (the league's own player id: nfl gsis, NBA and WNBA Stats ids, MLBAM, NHL), as in headshot_url.
**column_definition_kwargsAnyPassed to plottable.ColumnDefinition.

Returns​

plottable.ColumnDefinition — The column definition; an unknown id leaves its cell blank, with an SdvplotWarning.

Raises​

  • InputError: (a ValueError) When the table is drawn, if league has no ESPN headshots or id_system is not valid for it.
  • OfflineError: When the table is drawn, if a headshot, or with id_system="gsis" the nflverse player table, is neither cached nor downloadable (a DownloadError, also an OSError, for an HTTP error status).
  • UnsafeDownloadError: (an OSError) When the table is drawn, if a download is refused: larger than the byte cap, past the deadline, or redirected away from https.

Example​

import pandas as pd
from plottable import Table
from sdvplot.plottable import headshot_column

df = pd.DataFrame(
{
"team": ["KC", "BUF", "BAL"],
"espn_id": ["3139477", "3918298", "3916387"],
"wins": [12, 10, 9],
}
)

Table(df, column_definitions=[headshot_column("espn_id", league="nfl", title="")])

See also​

logo_column​

logo_column(
name: str,
*,
league: str,
season: Any = None,
variant: str = 'default',
mark_type: str = 'logo',
id_system: str = 'auto',
**column_definition_kwargs: Any,
) -> plottable.column_def.ColumnDefinition

A plottable column that shows each row's team as its logo (or wordmark).

Arguments​

NameTypeDescription
namestrThe data column holding the teams.
leaguestrThe SDV league key, e.g. "nfl".
seasonAnyOne season for every row.
variantstr"default", "dark", or a named variant from marks().
mark_typestr"logo" or "wordmark".
id_systemstrThe id system of the column's values.
**column_definition_kwargsAnyPassed to plottable.ColumnDefinition (title, width, group, ...).

Returns​

plottable.ColumnDefinition — The column definition; an unknown team leaves its cell blank, with an SdvplotWarning.

Raises​

  • InputError: (a ValueError) When the table is drawn, if mark_type is not "logo" or "wordmark", league, id_system or variant is unknown, or season is not a year or is outside the seasons sdvplot knows for the league (the column definition itself is built without checking them).
  • OfflineError: When the table is drawn, if the logo manifest or a mark's image is neither cached nor downloadable (a DownloadError, also an OSError, when the CDN answers with an error status; an IntegrityError when it sends a file that does not match the manifest's sha256, or one PIL cannot decode).
  • UnsafeDownloadError: (an OSError) When the table is drawn, if a download is refused: larger than the byte cap, past the deadline, or redirected away from https.
  • UnsafeCachePathError: (a ValueError) When the table is drawn, if the manifest's sha256 or extension for a mark would put the file outside the cache directory.
  • OptionalDependencyError: When the table is drawn, if a mark is an SVG and the svg extra is not installed.

Example​

from plottable import Table
from sdvplot.plottable import logo_column
import pandas as pd

df = pd.DataFrame(
{
"team": ["KC", "BUF", "BAL"],
"espn_id": ["3139477", "3918298", "3916387"],
"wins": [12, 10, 9],
}
)

Table(df, column_definitions=[logo_column("team", league="nfl", title="")])

See also​

plottable_sdv_theme​

plottable_sdv_theme(
name: str,
*,
mode: str = 'light',
) -> dict[str, Any]

The plottable.Table keywords that style a table like one of the 122 surveyed themes.

Arguments​

NameTypeDescription
namestrThe theme id, as listed by sdv_table_themes() (see table_theme_spec).
modestr"light" or "dark"; dark raises on a light-only theme.

Returns​

dict — Keywords for Table (textprops, row_dividers, row_divider_kw, col_label_divider, col_label_divider_kw, col_label_cell_kw, footer_divider, footer_divider_kw, column_border_kw, odd_row_color, even_row_color) plus facecolor, which Table does not accept: pop it and apply it with fig.set_facecolor (and ax.set_facecolor). col_label_cell_kw is the header fill (the theme's labelBg), empty unless body text keeps 3:1 contrast on it: plottable styles header text with the body textprops, so labelColor and labelWeight cannot be applied. A body font matplotlib cannot find falls back to its generic family (serif, monospace or sans-serif) with one UserWarning per family per process.

Raises​

  • InputError: As table_theme_spec: an unknown name or mode, or mode="dark" on a light-only theme.

Example​

import matplotlib.pyplot as plt
import pandas as pd
from plottable import Table
from sdvplot.plottable import plottable_sdv_theme

kw = plottable_sdv_theme("fangraphs")
fig, ax = plt.subplots()
fig.set_facecolor(kw.pop("facecolor"))
Table(pd.DataFrame({"team": ["KC", "BUF"], "wins": [12, 10]}), ax=ax, **kw)

See also​

  • sdvplot.table_theme_spec: the resolved spec
  • sdvplot.reactable.reactable_sdv_theme: the same themes for reactable