pandas.io.formats.style.Styler.text_gradient

pandas 3.1.1 · Styling · method

Color cell text according to numeric values and the selected color map.

Call syntax

Styler.text_gradient(…) Full signature
Styler.text_gradient(
    cmap='PuBu',
    low=0,
    high=0,
    axis=0,
    subset=None,
    vmin=None,
    vmax=None,
    gmap=None,
)

Inspect the call

Run this code to inspect the callable and its parameters. Its data, backend, or environment is needed to execute the operation itself.

Parameters

ParameterRequirementAccepted values and behavior
cmap Optional
Positional or keyword
Default 'PuBu'
str or colormap

Choose the color map used to translate values to colors.

low Optional
Positional or keyword
Default 0
float
high Optional
Positional or keyword
Default 0
float
axis Optional
Positional or keyword
Default 0
{0, 1, "index", "columns", None}

Choose which axis the operation acts on. The accepted axis labels depend on the receiver.

subset Optional
Positional or keyword
Default None
label, array-like, IndexSlice

Restrict the operation to these labels instead of considering the whole object.

vmin Optional
Positional or keyword
Default None
float

Set the lower boundary for the color range or normalization.

vmax Optional
Positional or keyword
Default None
float

Set the upper boundary for the color range or normalization.

gmap Optional
Positional or keyword
Default None
array-like

Returns

Styler

Example for a local Python session

import pandas as pd
import matplotlib
import jinja2
frame = pd.DataFrame({"units": [2., 5., 7.], "price": [4., 3., 2.]})
styled = frame.style
print(styled.text_gradient(cmap="Blues"))