matplotlib.axes.Axes.pie#

Axes.pie(x, *, explode=None, labels=None, colors=None, wedge_labels=None, wedge_label_distance=0.6, autopct=None, pctdistance=0.6, shadow=False, labeldistance=<UNSET>, startangle=0, radius=1, counterclock=True, wedgeprops=None, textprops=None, center=(0, 0), frame=False, rotatelabels=False, normalize=True, hatch=None, data=None)[source]#

Plot a pie chart.

Make a pie chart of array x. The fractional area of each wedge is given by x/sum(x).

The wedges are plotted counterclockwise, by default starting from the x-axis.

Parameters:
x1D array-like

The wedge sizes.

explodearray-like, default: None

If not None, is a len(x) array which specifies the fraction of the radius with which to offset each wedge.

labelslist, default: None

A sequence of strings providing the legend labels for each wedge.

Deprecated since version 3.12: In future these labels will not appear on the wedges but only be made available for the legend (see labeldistance below). To place labels on the wedges, use wedge_labels or the pie_label method.

colorscolor or list of color, default: None

A sequence of colors through which the pie chart will cycle. If None, will use the colors in the currently active cycle.

hatchstr or list, default: None

Hatching pattern applied to all pie wedges or sequence of patterns through which the chart will cycle. For a list of valid patterns, see Hatch style reference.

Added in version 3.7.

wedge_labelsstr or list of str, optional

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%})"

For more control or to add multiple sets of labels, use pie_label instead.

Added in version 3.12.

wedge_label_distancefloat, default: 0.6

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

Added in version 3.12.

autopctNone or str or callable, default: None

If not None, autopct is a string or function used to label the wedges with their numeric value. The label will be placed inside the wedge. If autopct is a format string, the label will be fmt % pct. If autopct is a function, then it will be called.

Discouraged

Consider using the wedge_labels parameter or pie_label method instead.

pctdistancefloat, default: 0.6

The relative distance along the radius at which the text generated by autopct is drawn. To draw the text outside the pie, set pctdistance > 1. This parameter is ignored if autopct is None.

labeldistancefloat or None, default: 1.1

The relative distance along the radius at which the labels are drawn. To draw the labels inside the pie, set labeldistance < 1. If set to None, labels are not drawn but are still stored for use in legend.

Deprecated since version 3.12: From v3.14 labeldistance will default to None and will later be removed altogether. Use wedge_labels and wedge_label_distance or the pie_label method instead.

shadowbool or dict, default: False

If bool, whether to draw a shadow beneath the pie. If dict, draw a shadow passing the properties in the dict to Shadow.

Added in version 3.8: shadow can be a dict.

startanglefloat, default: 0 degrees

The angle by which the start of the pie is rotated, counterclockwise from the x-axis.

radiusfloat, default: 1

The radius of the pie.

counterclockbool, default: True

Specify fractions direction, clockwise or counterclockwise.

wedgepropsdict, default: None

Dict of arguments passed to each patches.Wedge of the pie. For example, wedgeprops = {'linewidth': 3} sets the width of the wedge border lines equal to 3. By default, clip_on=False. When there is a conflict between these properties and other keywords, properties passed to wedgeprops take precedence.

textpropsdict, default: None

Dict of arguments to pass to the Text objects.

center(float, float), default: (0, 0)

The coordinates of the center of the chart.

framebool, default: False

Plot Axes frame with the chart if true.

rotatelabelsbool, default: False

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

normalizebool, default: True

When True, always make a full pie by normalizing x so that sum(x) == 1. False makes a partial pie if sum(x) <= 1 and raises a ValueError for sum(x) > 1.

dataindexable object, optional

If given, the following parameters also accept a string s, which is interpreted as data[s] if s is a key in data:

x, explode, labels, colors, wedge_labels

Returns:
PieContainer

Container with all the wedge patches and any associated text objects.

Changed in version 3.11: Previously the wedges and texts were returned in a tuple.

Notes

The pie chart will probably look best if the figure and Axes are square, or the Axes aspect is equal. This method sets the aspect ratio of the axis to "equal". The Axes aspect ratio can be controlled with Axes.set_aspect.

Examples using matplotlib.axes.Axes.pie#

Pie charts

Pie charts

Bar of pie

Bar of pie

Nested pie charts

Nested pie charts

A pie and a donut with labels

A pie and a donut with labels

Labeling pie charts

Labeling pie charts

SVG filter pie

SVG filter pie

pie(x)

pie(x)