We use cookies to improve your experience. If you continue to use our site, we'll assume that you're happy with it. :)

Coding a Pie Chart using Python

2 min read

Pie Chart is a Circular Graphic Formation, which is customizable and divided into slices to illustrate the numerical proportion. The Proportion can be in Percentage or Ratio.

This Pie Chart can help user to get proper ration of their task and work accordingly. Further (which is not discussed here), you can implement GUI in it and create a apk file. Simply, Convert your .py file to .apk easily.

Why Use Pie Chart?

Answer - Pie Charts can be used to show percentages graphically in the form of slices.

Today, We'll Demonstrate a Pie Chart which is build in Python Programming.

Python is a truly wonderful language. When somebody comes up with a good idea it takes about 1 minute and five lines to program something that almost does what you want. Then it takes only an hour to extend the script to 300 lines, after which it still does almost what you want. - Jack Jansen

Here I'll Provide Source Code for your Understanding -

So, Let's Get Started with Building a Pie Chart in Python.

For this Python Program, you'll need to import matplotlib.pyplot as plt.

Source Code - (Pie Chart)

import matplotlib.pyplot as plt
x=[30, 30, 20, 20]
la=["Satyaprakash","Aakash","Kamlesh", "Deepti"]
plt.pie(x,labels=la)
plt.show()

Output for the Following Code is Displayed Below.

How to Calculate a Pie Chart Mathematically?

Answer: To Calculate, Multiply the Percentage (%) of Slice by the Total Numbers of Data given and Divide it with 100.

This Portion or Line of the Code Represents Quantity or Numerical Percentage of Data-Set. 

x=[30, 30, 20, 20]

And the Code, represent the Data-Sets in Pie Chart.

la=["Satyaprakash","Aakash","Kamlesh", "Deepti"]

So, this was the Program for coding a Pie Chart in Python.

I will recommend you try this program on your own. You Can Copy/Paste the Code from Above.

Post a Comment