Skip to content

Gradients

Gradient methods map numeric values to colours along a colormap. See Colors & Colormaps for the full list of available cmap values.


gradient(in_col, scope="column", cmap="viridis", color=False, exclude=None)

Apply a sequential colour gradient. Values are normalised to [0, 1] then mapped to the colormap.

  • in_col str | list | Expr — Column(s) to apply to
  • scope "column" | "table", default "column" — Normalise per column or across all selected columns
  • cmap str, default "viridis" — Colormap name (see Colors & Colormaps)
  • color bool, default False — If True, also colour the text using the colormap
  • exclude str | list | None, default None — Columns to exclude

Example:

df.style().gradient("Revenue", cmap="viridis").show()
Company Revenue Profit Growth Employees_k
Apple 383.3 97.0 7.8 161
Microsoft 211.9 72.4 6.9 221
Google 307.4 73.8 8.7 182
Amazon 574.8 30.4 11.8 1541
Meta 134.9 39.1 16.4 67

gradient_divergent(in_col, center, scope="column", cmap="RdBu", color=False, exclude=None)

Apply a divergent colour gradient that splits at center. Values below center use the left half of the colormap; values above use the right half.

  • in_col str | list | Expr — Column(s) to apply to
  • center float — The neutral midpoint value
  • scope "column" | "table", default "column" — Normalise per column or across all selected
  • cmap str, default "RdBu" — Divergent colormap name
  • color bool, default False — Also colour text using the colormap
  • exclude str | list | None, default None — Columns to exclude

Example:

df.style().gradient_divergent("Cost_per_1M", center=15.0, cmap="vik").show()
Model MMLU HumanEval GPQA Context_k Cost_per_1M
GPT-4 86.4 67.0 50.1 128 30.0
Claude-3.5 Sonnet 88.7 92.0 59.4 200 3.0
Gemini-1.5 Pro 85.9 71.9 46.2 2048 7.0
Llama-3-70B 82.0 81.7 42.7 8 0.9
Mixtral-8x7B 70.6 40.2 34.3 32 0.7

gradient_between(in_col, low, high, scope="column", cmap="viridis", color=False, exclude=None)

Apply a gradient only within a specified range. Values outside [low, high] receive no colour.

  • in_col str | list | Expr — Column(s) to apply to
  • low float — Lower bound of the colour range
  • high float — Upper bound of the colour range
  • scope "column" | "table", default "column" — Normalise per column or globally
  • cmap str, default "viridis" — Colormap name
  • color bool, default False — Also colour text
  • exclude str | list | None, default None — Columns to exclude

Example:

df.style().gradient_between("Revenue", low=100.0, high=400.0, cmap="lapaz").show()
Company Revenue Profit Growth Employees_k
Apple 383.3 97.0 7.8 161
Microsoft 211.9 72.4 6.9 221
Google 307.4 73.8 8.7 182
Amazon 574.8 30.4 11.8 1541
Meta 134.9 39.1 16.4 67

heat_map(in_col=pl.all(), cmap="viridis", color=False, exclude=None)

Apply a gradient across all (or selected) numeric columns simultaneously with a shared scale. Convenience wrapper around gradient(scope="table").

  • in_col str | list | Expr, default pl.all() — Column(s) to apply to (defaults to all numeric)
  • cmap str, default "viridis" — Colormap name
  • color bool, default False — Also colour text
  • exclude str | list | None, default None — Columns to exclude from pl.all()

Example:

df.select(["Revenue", "Profit", "Growth"]).style().heat_map().show()
Revenue Profit Growth
383.3 97.0 7.8
211.9 72.4 6.9
307.4 73.8 8.7
574.8 30.4 11.8
134.9 39.1 16.4