gt-extras
  • Intro
  • Examples
  • API Reference
  1. Plotting
  2. gt_plt_donut
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_bar_pct
    • gt_plt_bar_stack
    • gt_plt_bullet
    • gt_plt_conf_int
    • gt_plt_donut
    • gt_plt_dot
    • gt_plt_dumbbell
    • gt_plt_summary
    • gt_plt_winloss
  • Colors
    • gt_color_box
    • gt_data_color_by_group
    • gt_highlight_cols
    • gt_highlight_rows
    • gt_hulk_col_numeric
  • Themes
    • gt_theme_538
    • gt_theme_dark
    • gt_theme_dot_matrix
    • gt_theme_espn
    • gt_theme_excel
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_pff
  • Icons and Images
    • add_text_img
    • fa_icon_repeat
    • gt_fa_rank_change
    • gt_fa_rating
    • gt_fmt_img_circle
    • img_header
  • Utilities
    • fmt_pct_extra
    • gt_add_divider
    • gt_duplicate_column
    • gt_merge_stack
    • gt_two_column_layout
    • with_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  • Note
  1. Plotting
  2. gt_plt_donut

gt_plt_donut

gt_plt_donut(
    gt,
    columns=None,
    fill='purple',
    size=30,
    stroke_color=None,
    stroke_width=1,
    show_labels=False,
    label_color='black',
    domain=None,
    keep_columns=False,
)

Create donut charts in GT cells.

The gt_plt_donut() function takes an existing GT object and adds donut charts to specified columns. Each cell value is represented as a portion of a full donut chart, with the chart size proportional to the cell’s numeric value relative to the column’s maximum value. The maximum value in the column will display as a full circle.

Parameters

gt : GT

A GT object to modify.

columns : SelectExpr = None

The columns to target. Can be a single column or a list of columns (by name or index). If None, the donut chart is applied to all numeric columns.

fill : str = 'purple'

The fill color for the donut chart segments.

size : float = 30

The diameter of the donut chart in pixels.

stroke_color : str | None = None

The color of the border around the donut chart. If None, no stroke will be drawn, except for the case of the 0 value.

stroke_width : float = 1

The width of the border stroke in pixels.

show_labels : bool = False

Whether or not to show labels on the donut charts.

label_color : str = 'black'

The color of text labels on the donut charts (when show_labels is True).

domain : list[int] | list[float] | None = None

The domain of values to use for scaling. This can be a list of floats or integers. If None, the domain is automatically set to [0, max(column_values)].

keep_columns : bool = False

Whether to keep the original column values. If this flag is True, the plotted values will be duplicated into a new column with the string ” plot” appended to the end of the column name. See gt_duplicate_column() for more details.

Returns

: GT

A GT object with donut charts added to the specified columns.

Examples

from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte

gtcars_mini = gtcars.loc[
    9:17,
    ["model", "mfr", "year", "hp", "hp_rpm", "trq", "trq_rpm", "mpg_c", "mpg_h"]
]

gt = (
    GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label="Car")
    .cols_align("center")
    .cols_align("left", columns="mfr")
)

gt.pipe(
    gte.gt_plt_donut,
    columns=["hp", "hp_rpm", "trq", "trq_rpm", "mpg_c", "mpg_h"],
    size=40,
    fill="steelblue"
)
Car mfr year hp hp_rpm trq trq_rpm mpg_c mpg_h
LaFerrari Ferrari 2015
NSX Acura 2017
GT-R Nissan 2016
Aventador Lamborghini 2015
Huracan Lamborghini 2015
Gallardo Lamborghini 2014
Continental GT Bentley 2016
Granturismo Maserati 2016
Quattroporte Maserati 2016

Note

Each column’s donut charts are scaled independently based on that column’s min/max values. A value equal to the column maximum will display as a full circle (360 degrees).

gt_plt_conf_int
gt_plt_dot