matplotlib.axes.Axes.bar_label#

Axes.bar_label(container,labels=None,*,fmt='%g',label_type='edge',padding=0,**kwargs)[source]#

Label a bar plot.

Adds labels to bars in the givenBarContainer.You may need to adjust the axis limits to fit the labels.

Parameters:
containerBarContainer

Container with all the bars and optionally errorbars, likelyreturned frombar orbarh.

labelsarray-like, optional

A list of label texts, that should be displayed. If not given, thelabel texts will be the data values formatted withfmt.

fmtstr or callable, default: '%g'

An unnamed %-style or {}-style format string for the label or afunction to call with the value as the first argument.Whenfmt is a string and can be interpreted in both formats,%-style takes precedence over {}-style.

Added in version 3.7:Support for {}-style format string and callables.

label_type{'edge', 'center'}, default: 'edge'

The label type. Possible values:

  • 'edge': label placed at the end-point of the bar segment, and thevalue displayed will be the position of that end-point.

  • 'center': label placed in the center of the bar segment, and thevalue displayed will be the length of that segment.(useful for stacked bars, i.e.,Bar chart with labels)

paddingfloat, default: 0

Distance of label from the end of the bar, in points.

**kwargs

Any remaining keyword arguments are passed through toAxes.annotate. The alignment parameters (horizontalalignment /ha,verticalalignment /va) arenot supported because the labels are automatically aligned tothe bars.

Returns:
list ofAnnotation

A list ofAnnotation instances for the labels.

Examples usingmatplotlib.axes.Axes.bar_label#

Bar chart with labels

Bar chart with labels

Grouped bar chart with labels

Grouped bar chart with labels

Discrete distribution as horizontal bar chart

Discrete distribution as horizontal bar chart

Bar of pie

Bar of pie