@staticmethod
def _background_gradient(s, cmap='PuBu', low=0, high=0, text_color_threshold=0.408):
    '\n        Color background in a range according to the data.\n        '
    if ((not isinstance(text_color_threshold, (float, int))) or (not (0 <= text_color_threshold <= 1))):
        msg = '`text_color_threshold` must be a value from 0 to 1.'
        raise ValueError(msg)
    with _mpl(Styler.background_gradient) as (plt, colors):
        smin = s.values.min()
        smax = s.values.max()
        rng = (smax - smin)
        norm = colors.Normalize((smin - (rng * low)), (smax + (rng * high)))
        rgbas = plt.cm.get_cmap(cmap)(norm(s.values))

        def relative_luminance(rgba):
            '\n                Calculate relative luminance of a color.\n\n                The calculation adheres to the W3C standards\n                (https://www.w3.org/WAI/GL/wiki/Relative_luminance)\n\n                Parameters\n                ----------\n                color : rgb or rgba tuple\n\n                Returns\n                -------\n                float\n                    The relative luminance as a value from 0 to 1\n                '
            (r, g, b) = (((x / 12.92) if (x <= 0.03928) else ((x + 0.055) / (1.055 ** 2.4))) for x in rgba[:3])
            return (((0.2126 * r) + (0.7152 * g)) + (0.0722 * b))

        def css(rgba):
            dark = (relative_luminance(rgba) < text_color_threshold)
            text_color = ('#f1f1f1' if dark else '#000000')
            return 'background-color: {b};color: {c};'.format(b=colors.rgb2hex(rgba), c=text_color)
        if (s.ndim == 1):
            return [css(rgba) for rgba in rgbas]
        else:
            return pd.DataFrame([[css(rgba) for rgba in row] for row in rgbas], index=s.index, columns=s.columns)
Color background in a range according to the data.
@staticmethod
def _background_gradient(s, cmap='PuBu', low=0, high=0, text_color_threshold=0.408):
    '\n        \n        '
    if ((not isinstance(text_color_threshold, (float, int))) or (not (0 <= text_color_threshold <= 1))):
        msg = '`text_color_threshold` must be a value from 0 to 1.'
        raise ValueError(msg)
    with _mpl(Styler.background_gradient) as (plt, colors):
        smin = s.values.min()
        smax = s.values.max()
        rng = (smax - smin)
        norm = colors.Normalize((smin - (rng * low)), (smax + (rng * high)))
        rgbas = plt.cm.get_cmap(cmap)(norm(s.values))

        def relative_luminance(rgba):
            '\n                Calculate relative luminance of a color.\n\n                The calculation adheres to the W3C standards\n                (https://www.w3.org/WAI/GL/wiki/Relative_luminance)\n\n                Parameters\n                ----------\n                color : rgb or rgba tuple\n\n                Returns\n                -------\n                float\n                    The relative luminance as a value from 0 to 1\n                '
            (r, g, b) = (((x / 12.92) if (x <= 0.03928) else ((x + 0.055) / (1.055 ** 2.4))) for x in rgba[:3])
            return (((0.2126 * r) + (0.7152 * g)) + (0.0722 * b))

        def css(rgba):
            dark = (relative_luminance(rgba) < text_color_threshold)
            text_color = ('#f1f1f1' if dark else '#000000')
            return 'background-color: {b};color: {c};'.format(b=colors.rgb2hex(rgba), c=text_color)
        if (s.ndim == 1):
            return [css(rgba) for rgba in rgbas]
        else:
            return pd.DataFrame([[css(rgba) for rgba in row] for row in rgbas], index=s.index, columns=s.columns)