pandas.io.formats.style.Styler.background_gradient
-
Styler.background_gradient(cmap='PuBu', low=0, high=0, axis=0, subset=None, text_color_threshold=0.408)
[source] -
Color the background in a gradient according to the data in each column (optionally row).
Requires matplotlib.
Parameters: -
cmap : str or colormap
-
matplotlib colormap
-
low, high : float
-
compress the range by these values.
-
axis : int or str
-
1 or ‘columns’ for columnwise, 0 or ‘index’ for rowwise
-
subset : IndexSlice
-
a valid slice for
data
to limit the style application to -
text_color_threshold : float or int
-
luminance threshold for determining text color. Facilitates text visibility across varying background colors. From 0 to 1. 0 = all text is dark colored, 1 = all text is light colored.
New in version 0.24.0.
Returns: -
self : Styler
Raises: - ValueError
-
If
text_color_threshold
is not a value from 0 to 1.
Notes
Set
text_color_threshold
or tunelow
andhigh
to keep the text legible by not using the entire range of the color map. The range of the data is extended bylow * (x.max() - x.min())
andhigh * (x.max() - x.min())
before normalizing. -
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.io.formats.style.Styler.background_gradient.html