matplotlib.pyplot.pie_label#

matplotlib.pyplot.pie_label(container, /, labels, *, distance=0.6, textprops=None, rotate=False, alignment='auto')[source]#

Label a pie chart.

Added in version 3.11.

Adds labels to wedges in the given PieContainer.

Parameters:
containerPieContainer

Container with all the wedges, likely returned from pie.

labelsstr or list of str

A sequence of strings providing the labels for each wedge, or a format string with absval and/or frac placeholders. For example, to label each wedge with its value and the percentage in brackets:

wedge_labels="{absval:d} ({frac:.0%})"
distancefloat, default: 0.6

The radial position of the labels, relative to the pie radius. Values > 1 are outside the wedge and values < 1 are inside the wedge.

textpropsdict, default: None

Dict of arguments to pass to the Text objects.

rotatebool, default: False

Rotate each label to the angle of the corresponding slice if true.

alignment{'center', 'outer', 'auto'}, default: 'auto'

Controls the horizontal alignment of the text objects relative to their nominal position.

  • 'center': The labels are centered on their points.

  • 'outer': Labels are aligned away from the center of the pie, i.e., labels on the left side of the pie are right-aligned and labels on the right side are left-aligned.

  • 'auto': Translates to 'outer' if distance > 1 (so that the labels do not overlap the wedges) and 'center' if distance < 1.

If rotate is True, the vertical alignment is also affected in an analogous way.

  • 'center': The labels are centered on their points.

  • 'outer': Labels are aligned away from the center of the pie, i.e., labels on the top half of the pie are bottom-aligned and labels on the bottom half are top-aligned.

Returns:
list

A list of the label Text instances.

Notes

Note

This is the pyplot wrapper for axes.Axes.pie_label.

Examples using matplotlib.pyplot.pie_label#

A pie and a donut with labels

A pie and a donut with labels

Labeling pie charts

Labeling pie charts