A Pie Chart is a circular statistical plot that can display only one series of data. The area of the chart is the total percentage of the given data. The area of slices of the pie represents the percentage of the parts of the data. The slices of pie are called wedges. The area of the wedge is determined by the length of the arc of the wedge. The area of a wedge represents the relative percentage of that part with respect to whole data. Pie charts are commonly used in business presentations like sales, operations, survey results, resources, etc as they provide a quick summary.
Creating Pie Chart
Matplotlib API has
pie() function in its
pyplot module which create a pie chart representing the data in an array.
Syntax: matplotlib.pyplot.pie(data, explode=None, labels=None, colors=None, autopct=None, shadow=False)
data represents the array of data values to be plotted, the fractional area of each slice is represented by data/sum(data). If sum(data)<1, then the data values returns the fractional area directly, thus resulting pie will have empty wedge of size 1-sum(data).
labels is a list of sequence of strings which sets the label of each wedge.
color attribute is used to provide color to the wedges.
autopct is a string used to label the wedge with their numerical value.
shadow is used to create shadow of wedge.
Let’s create a simple pie chart using the
Customizing Pie Chart
A pie chart can be customized on the basis several aspects. The
startangle attribute rotates the plot by the specified degrees in counter clockwise direction performed on x-axis of pie chart.
shadow attribute accepts boolean value, if its true then shadow will appear below the rim of pie. Wedges of the pie can be customized using
wedgeprop which takes Python dictionary as parameter with name values pairs denoting the wedge properties like linewidth, edgecolor, etc. By setting
frame=True axes frame is drawn aroun the pie chart.
autopct controls how the percentages are displayed on the wedges. Let us try to modify the above plot:
Example 2: Creating a Nested Pie Chart
- Python Bokeh - Making a Pie Chart
- Pie plot using Plotly in Python
- Multi-Series Pie Chart in Pygal
- Pie chart in Pygal
- Half pie chart in Pygal
- Plot Candlestick Chart using mplfinance module in Python
- matplotlib.axes.Axes.pie() in Python
- PyQtGraph - Getting Plot Item from Plot Window
- Python | Basic Gantt chart using Matplotlib
- Line chart in Matplotlib - Python
- Python | Plotting Pie charts in excel sheet using XlsxWriter module
- Make a violin plot in Python using Matplotlib
- Plot the magnitude spectrum in Python using Matplotlib
- Plot the phase spectrum in Python using Matplotlib
- Plot Mathematical Expressions in Python using Matplotlib
- Plot the power spectral density using Matplotlib - Python
- Contour Plot using Matplotlib - Python
- Box Plot in Python using Matplotlib
- Simple Plot in Python using Matplotlib
- Plot 2-D Histogram in Python using Matplotlib
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.