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 givenPieContainer.

Parameters:
containerPieContainer

Container with all the wedges, likely returned frompie.

labelsstr or list of str

A sequence of strings providing the labels for each wedge, or a formatstring withabsval and/orfrac placeholders. For example, to labeleach 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 > 1are outside the wedge and values < 1 are inside the wedge.

textpropsdict, default: None

Dict of arguments to pass to theText 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 theirnominal position.

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

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

  • 'auto': Translates to 'outer' ifdistance > 1 (so that the labels do notoverlap the wedges) and 'center' ifdistance < 1.

Ifrotate is True, the vertical alignment is also affected in ananalogous way.

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

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

Returns:
list

A list of the labelText instances.

Notes

Examples usingmatplotlib.pyplot.pie_label#

A pie and a donut with labels

A pie and a donut with labels

Labeling pie charts

Labeling pie charts