sdvplot.plottable
plottable columns of team logos, wordmarks and player headshots.
| Name | What it is |
|---|---|
| headshot_column | A plottable column that shows each row's player as a headshot. |
| logo_column | A plottable column that shows each row's team as its logo (or wordmark). |
| plottable_sdv_theme | The 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
| Name | Type | Description |
|---|---|---|
name | str | The data column holding the player ids. |
league | str | The SDV league key, e.g. "nfl". |
id_system | str | "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_kwargs | Any | Passed 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, ifleaguehas no ESPN headshots orid_systemis not valid for it.OfflineError: When the table is drawn, if a headshot, or withid_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
- sdvplotR geom_nfl_headshots()
- sdvplot.plottable.logo_column: the same with team logos
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
| Name | Type | Description |
|---|---|---|
name | str | The data column holding the teams. |
league | str | The SDV league key, e.g. "nfl". |
season | Any | One season for every row. |
variant | str | "default", "dark", or a named variant from marks(). |
mark_type | str | "logo" or "wordmark". |
id_system | str | The id system of the column's values. |
**column_definition_kwargs | Any | Passed 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, ifmark_typeis not "logo" or "wordmark",league,id_systemorvariantis unknown, orseasonis 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 thesvgextra 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
| Name | Type | Description |
|---|---|---|
name | str | The theme id, as listed by sdv_table_themes() (see table_theme_spec). |
mode | str | "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: Astable_theme_spec: an unknown name or mode, ormode="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