Skip to main content
`Ctrl`+`K`

# pandas.io.formats.style.Styler.bar

Styler.bar(subset=None, axis=0, *, color=None, cmap=None, width=100, height=100, align='mid', vmin=None, vmax=None, props='width: 10em;')

  Draw bar chart in the cell backgrounds.

  Changed in version 1.4.0.

  Parameters:
    subsetlabel, array-like, IndexSlice, optional

      A valid 2d input to DataFrame.loc[<subset>], or, in the case of a 1d input or single key, to DataFrame.loc[:, <subset>] where the columns are prioritised, to limit `data` to before applying the function.

    axis{0 or ‘index’, 1 or ‘columns’, None}, default 0

      Apply to each column (`axis=0` or `'index'`), to each row (`axis=1` or `'columns'`), or to the entire DataFrame at once with `axis=None`.

    colorstr or 2-tuple/list

      If a str is passed, the color is the same for both negative and positive numbers. If 2-tuple/list is used, the first element is the color_negative and the second is the color_positive (eg: [‘#d65f5f’, ‘#5fba7d’]).

    cmapstr, matplotlib.cm.ColorMap

      A string name of a matplotlib Colormap, or a Colormap object. Cannot be used together with `color`.

      Added in version 1.4.0.

    widthfloat, default 100

      The percentage of the cell, measured from the left, in which to draw the bars, in [0, 100].

    heightfloat, default 100

      The percentage height of the bar in the cell, centrally aligned, in [0,100].

      Added in version 1.4.0.

    alignstr, int, float, callable, default ‘mid’

      How to align the bars within the cells relative to a width adjusted center. If string must be one of:

      - ‘left’ : bars are drawn rightwards from the minimum data value.

      - ‘right’ : bars are drawn leftwards from the maximum data value.

      - ‘zero’ : a value of zero is located at the center of the cell.

      - ‘mid’ : a value of (max-min)/2 is located at the center of the cell, or if all values are negative (positive) the zero is aligned at the right (left) of the cell.

      - ‘mean’ : the mean value of the data is located at the center of the cell.

      If a float or integer is given this will indicate the center of the cell.

      If a callable should take a 1d or 2d array and return a scalar.

      Changed in version 1.4.0.

    vminfloat, optional

      Minimum bar value, defining the left hand limit of the bar drawing range, lower values are clipped to vmin. When None (default): the minimum value of the data will be used.

    vmaxfloat, optional

      Maximum bar value, defining the right hand limit of the bar drawing range, higher values are clipped to vmax. When None (default): the maximum value of the data will be used.

    propsstr, optional

      The base CSS of the cell that is extended to add the bar chart. Defaults to “width: 10em;”.

      Added in version 1.4.0.

  Returns:
    Styler

  Notes

  This section of the user guide: Table Visualization gives a number of examples for different settings and color coordination.

  Examples

      >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
      >>> df.style.bar(subset=['A'], color='gray')