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_colstr | list | Expr— Column(s) to apply toscope"column" | "table", default"column"— Normalise per column or across all selected columnscmapstr, default"viridis"— Colormap name (see Colors & Colormaps)colorbool, defaultFalse— If True, also colour the text using the colormapexcludestr | list | None, defaultNone— 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 |
| 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_colstr | list | Expr— Column(s) to apply tocenterfloat— The neutral midpoint valuescope"column" | "table", default"column"— Normalise per column or across all selectedcmapstr, default"RdBu"— Divergent colormap namecolorbool, defaultFalse— Also colour text using the colormapexcludestr | list | None, defaultNone— 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_colstr | list | Expr— Column(s) to apply tolowfloat— Lower bound of the colour rangehighfloat— Upper bound of the colour rangescope"column" | "table", default"column"— Normalise per column or globallycmapstr, default"viridis"— Colormap namecolorbool, defaultFalse— Also colour textexcludestr | list | None, defaultNone— 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 |
| 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_colstr | list | Expr, defaultpl.all()— Column(s) to apply to (defaults to all numeric)cmapstr, default"viridis"— Colormap namecolorbool, defaultFalse— Also colour textexcludestr | list | None, defaultNone— Columns to exclude frompl.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 |