Draw a pie chart that shows our daily activity in Python

Here, we will perceive how to draw a pie outline that shows our day by day action in the Python programming language?

The pie outline speaks to the amount in rates, and the all-out aggregate of the considerable number of fragments of the pie diagram must be equivalent to 100%.

It is utilized to envision the given information in rate. The client will give us one rundown of day by day exercises and another rundown that shows the time taken day by day to do every action and by utilizing these rundowns we need to draw a pie diagram by utilizing the Python.

One thing will strike a chord that to draw a pie outline of day by day movement, at first, we need to figure the level of every action time at that point draw the pie graph and it will require some investment.

Truly, this methodology certainly will take a great deal of time and that is the reason we won’t go for this methodology. In this way, don’t stress over it since Python gives us an in-manufactured matplotlib library which makes it so a lot simpler.

Before utilizing the matplotlib library in the program, we will see a smidgen about it and the establishment procedure.

matplotlib library is one of the most helpful libraries of Python. It is utilized for the perception of the given information in 2D plots.

By utilizing this, we can draw plots, pie graphs, histograms, scatterplots, and so on.

Algorithm to take care of this issue:

  • Import pyplot module from the matplotlib library as plt.
  • Take the day by day movement and time taken to do the action in two arrays.
  • Presently, draw the pie diagram with the title ‘Pie graph of everyday action’.

In this way, how about we start composing a couple of lines of code in Python by executing the above algorithm in a basic manner.

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:

Draw a pie chart that shows our daily activity in Python

Leave a Comment

error: Alert: Content is protected!!