Q:

Draw a pie chart that shows our daily activity in Python

belongs to collection: Python basic programs

0

The pie chart represents the quantity in percentages, and the total sum of all the segments of the pie chart must be equal to 100%. It is used to visualize the given data in percentage. The user will provide us one list of daily activities and another list that shows the time taken daily to do each activity and by using these lists we have to draw a pie chart by using the Python. One thing will come to your mind that to draw a pie chart of daily activity, initially, we have to calculate the percentage of each activity time then draw the pie chart and it will take a lot of time. Yes, this approach definitely will take a lot of time and that's why we will not go for this approach. So, don't worry about it because Python provides us an in-built matplotlib library which makes it so much easier. Before using the matplotlib library in the program, we will see a little bit about it and the installation process.

matplotlib library is one of the most useful libraries of Python. It is used for visualization of given data in 2D plots. By using this, we can draw plots, pie charts, histograms, scatterplots, etc.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

import matplotlib.pyplot as plt

A=['eat', 'movie', 'study', 'play','daily_work','sleep']
T=[1,3,5,4,2,9]

plt.pie(T, labels=A,autopct= '%1.1f%%')
plt.title('Pie chart of daily activity.')
plt.show()

Output

Pie Chart in Python

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Find the sum of all numbers below 1000 which are m... >>
<< Check whether the binary representation of a given...