gt-extras
  • Get Started
  • API Reference
  1. Colors
  2. gt_hulk_col_numeric
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_dot
  • Colors
    • gt_highlight_cols
    • gt_hulk_col_numeric
    • gt_color_box
  • Themes
    • gt_theme_538
    • gt_theme_espn
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_excel
    • gt_theme_dot_matrix
    • gt_theme_dark
    • gt_theme_pff
  • Icons and Images
    • fa_icon_repeat
    • gt_fa_rating
  • HTML Helpers
    • gt_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  1. Colors
  2. gt_hulk_col_numeric

gt_hulk_col_numeric

gt_hulk_col_numeric(
    gt,
    columns=None,
    palette='PRGn',
    domain=None,
    na_color=None,
    alpha=None,
    reverse=False,
    autocolor_text=True,
)

Apply a color gradient to numeric columns in a GT object.

The gt_hulk_col_numeric() function takes an existing GT object and applies a color gradient to the background of specified numeric columns, based on their values. This is useful for visually emphasizing the distribution or magnitude of numeric data within a table.

Parameters

gt : GT

An existing GT object.

columns : SelectExpr = None

The columns to target. Can be a single column name or a list of column names. If None, the color gradient is applied to all columns.

palette : str | list[str] = 'PRGn'

The color palette to use for the gradient. Can be a string referencing a palette name or a list of color hex codes. Defaults to the "PRGn" palette from the ColorBrewer package.

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

The range of values to map to the color palette. Should be a list of two values (min and max). If None, the domain is inferred from the data.

na_color : str | None = None

The color to use for missing (NA) values. If None, a default color is used.

alpha : int | float | None = None

The alpha (transparency) value for the colors, as a float between 0 (fully transparent) and 1 (fully opaque).

reverse : bool = False

If True, reverses the color palette direction.

autocolor_text : bool = True

If True, automatically adjusts text color for readability against the background.

Returns

: GT

The modified GT object, allowing for method chaining.

Examples

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

gtcars_mini = gtcars[["model", "year", "hp", "trq"]].head(9)

gt = (
    GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label="Car")
)

gte.gt_hulk_col_numeric(gt, columns=["hp", "trq"])
Car year hp trq
GT 2017 647.0 550.0
458 Speciale 2015 597.0 398.0
458 Spider 2015 562.0 398.0
458 Italia 2014 562.0 398.0
488 GTB 2016 661.0 561.0
California 2015 553.0 557.0
GTC4Lusso 2017 680.0 514.0
FF 2015 652.0 504.0
F12Berlinetta 2015 731.0 509.0
gt_highlight_cols
gt_color_box