Styling a Table#

By supplying keywords to the Table you can adjust its style:

"""
Args:
    df (pd.DataFrame):
        A pandas DataFrame with your table data
    ax (mpl.axes.Axes, optional):
        matplotlib axes. Defaults to None.
    index_col (str, optional):
        column to set as the DataFrame index. Defaults to None.
    columns (List[str], optional):
        columns to use. If None defaults to all columns.
    column_definitions (List[plottable.column_def.ColumnDefinition], optional):
        ColumnDefinitions for columns that should be styled. Defaults to None.
    textprops (Dict[str, Any], optional):
        textprops are passed to each TextCells matplotlib.pyplot.text. Defaults to {}.
    cell_kw (Dict[str, Any], optional):
        cell_kw are passed to to each cells matplotlib.patches.Rectangle patch.
        Defaults to {}.
    col_label_cell_kw (Dict[str, Any], optional):
        col_label_cell_kw are passed to to each ColumnLabels cells
        matplotlib.patches.Rectangle patch. Defaults to {}.
    col_label_divider (bool, optional):
        Whether to plot a divider line below the column labels. Defaults to True.
    col_label_divider_kw (Dict[str, Any], optional):
        col_label_divider_kw are passed to plt.plot. Defaults to {}.
    footer_divider (bool, optional):
        Whether to plot a divider line below the table. Defaults to False.
    footer_divider_kw (Dict[str, Any], optional):
        footer_divider_kw are passed to plt.plot. Defaults to {}.
    row_dividers (bool, optional):
        Whether to plot divider lines between rows. Defaults to True.
    row_divider_kw (Dict[str, Any], optional):
        row_divider_kw are passed to plt.plot. Defaults to {}.
    column_border_kw (Dict[str, Any], optional):
        column_border_kw are passed to plt.plot. Defaults to {}.
    even_row_color (str | Tuple, optional):
        facecolor of the even row cell's patches
    odd_row_color (str | Tuple, optional):
        facecolor of the even row cell's patches
"""

Column Definitions#

You can pass a list of ColumnDefinition’s to the column_definitions argument.

See also

How to use ColumnDefinition is documented in the Using ColumnDefinition Notebook

Textprops#

With textprops such as fontsize, fontname and color you can adjust the appearance of table text globally for the whole table. They are passed to all cell’s texts and only overridden by a ColumnDefinition’s textprops.

Cell Keywords#

With cell_kw such as facecolor, edgecolor and linewidth you can adjust the appearance of table cells globally. They are passed to all cell’s rectangle patches.

With col_label_cell_kw you can similarly adjust the appearance of the column label cells.

Row Divider Lines#

With boolean arguments col_label_divider, footer_divider and row_dividers you can plot divider lines between table rows.

By passing arguments to their respective keyword arguments - col_label_divider_kw, footer_divider_kw and row_dividers_kw - you can further style the divider lines. Keywords are passed to plt.plot.

Column Border Keywords#

Similarly you can pass a column_border_kw dictionary to Table to style the vertical divider lines between Column’s. Keywords are passed to plt.plot.

Tip

Mind that they are only applied to Column’s that have a border attribute specified in their ColumnDefinition.
You can find an example of plotting column borders in the Women’s World Cup Example

Row Colors#

With the even_row_color and odd_row_color arguments you can color each respective rows cell colors with the color you passed.

See also

You can find an example in the Basic Example Notebook