matplotlib.axes.Axes.pie#

Axes.pie(x,*,explode=None,labels=None,colors=None,autopct=None,pctdistance=0.6,shadow=False,labeldistance=1.1,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 arrayx. The fractional area of each wedge isgiven byx/sum(x).

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

Parameters:
x1D array-like

The wedge sizes.

explodearray-like, default: None

If notNone, is alen(x) array which specifies the fractionof the radius with which to offset each wedge.

labelslist, default: None

A sequence of strings providing the labels for each wedge

colorscolor or list ofcolor, default: None

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

hatchstr or list, default: None

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

Added in version 3.7.

autopctNone or str or callable, default: None

If notNone,autopct is a string or function used to label thewedges with their numeric value. The label will be placed insidethe wedge. Ifautopct is a format string, the label will befmt%pct. Ifautopct is a function, then it will be called.

pctdistancefloat, default: 0.6

The relative distance along the radius at which the textgenerated byautopct is drawn. To draw the text outside the pie,setpctdistance > 1. This parameter is ignored ifautopct isNone.

labeldistancefloat or None, default: 1.1

The relative distance along the radius at which the labels aredrawn. To draw the labels inside the pie, setlabeldistance < 1.If set toNone, labels are not drawn but are still stored foruse inlegend.

shadowbool or dict, default: False

If bool, whether to draw a shadow beneath the pie. If dict, draw a shadowpassing the properties in the dict toShadow.

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 eachpatches.Wedge of the pie.For example,wedgeprops={'linewidth':3} sets the width ofthe wedge border lines equal to 3. By default,clip_on=False.When there is a conflict between these properties and otherkeywords, properties passed towedgeprops 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

WhenTrue, always make a full pie by normalizing x so thatsum(x)==1.False makes a partial pie ifsum(x)<=1and raises aValueError forsum(x)>1.

dataindexable object, optional

If given, the following parameters also accept a strings, which isinterpreted asdata[s] ifs is a key indata:

x,explode,labels,colors

Returns:
patcheslist

A sequence ofmatplotlib.patches.Wedge instances

textslist

A list of the labelText instances.

autotextslist

A list ofText instances for the numeric labels. This will onlybe returned if the parameterautopct is notNone.

Notes

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

Examples usingmatplotlib.axes.Axes.pie#

SVG filter pie

SVG filter pie

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

Pie charts

Pie charts

pie(x)

pie(x)