- Matplotlib - Transforms
- Matplotlib - Working with Images
- Mathematical Expressions
- Matplotlib - Working With Text
- Matplotlib - 3D Surface plot
- Matplotlib - 3D Wireframe plot
- Matplotlib - 3D Contour Plot
- Three-dimensional Plotting
- Matplotlib - Violin Plot
- Matplotlib - Box Plot
- Matplotlib - Quiver Plot
- Matplotlib - Contour Plot
- Matplotlib - Scatter Plot
- Matplotlib - Pie Chart
- Matplotlib - Histogram
- Matplotlib - Bar Plot
- Matplotlib - Twin Axes
- Setting Ticks and Tick Labels
- Matplotlib - Setting Limits
- Matplotlib - Formatting Axes
- Matplotlib - Grids
- Matplotlib - Subplot2grid() Function
- Matplotlib - Subplots() Function
- Matplotlib - Multiplots
- Matplotlib - Axes Class
- Matplotlib - Figure Class
- Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Simple Plot
- Matplotlib - Pyplot API
- Matplotlib - Jupyter Notebook
- Matplotlib - Anaconda distribution
- Matplotlib - Environment Setup
- Matplotlib - Introduction
- Matplotlib - Home
Matplotlib Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Matplotpb - Pie Chart
A Pie Chart can only display one series of data. Pie charts show the size of items (called wedge) in one data series, proportional to the sum of the items. The data points in a pie chart are shown as a percentage of the whole pie.
Matplotpb API has a pie() function that generates a pie diagram representing data in an array. The fractional area of each wedge is given by x/sum(x). If sum(x)< 1, then the values of x give the fractional area directly and the array will not be normapzed. Theresulting pie will have an empty wedge of size 1 - sum(x).
The pie chart looks best if the figure and axes are square, or the Axes aspect is equal.
Parameters
Following table psts down the parameters foe a pie chart −
x | array-pke. The wedge sizes. |
labels | pst. A sequence of strings providing the labels for each wedge. |
Colors | A sequence of matplotpbcolorargs through which the pie chart will cycle. If None, will use the colors in the currently active cycle. |
Autopct | string, used to label the wedges with their numeric value. The label will be placed inside the wedge. The format string will be fmt%pct. |
Following code uses the pie() function to display the pie chart of the pst of students enrolled for various computer language courses. The proportionate percentage is displayed inside the respective wedge with the help of autopct parameter which is set to %1.2f%.
from matplotpb import pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_axes([0,0,1,1]) ax.axis( equal ) langs = [ C , C++ , Java , Python , PHP ] students = [23,17,35,29,12] ax.pie(students, labels = langs,autopct= %1.2f%% ) plt.show()Advertisements