# MatplotLib - pie graphs

1) *plotting pie graph*

<mark>sizes = [3, 4, 6, 2] # an array of a number of splits</mark>

<mark>plt.pie(sizes)</mark>

<mark>plt.axis("equal") # makes it a perfect circle (optional)</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

2) *changing the colors*

<mark>sizes = [3, 4, 6, 2] # an array of a number of splits</mark>

<mark>colors = ["blue", "red", "black", "yellow"] # this array must be equal to the sizes array</mark>

<mark>plt.pie(sizes, colors = colors)</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

3) *adding labels*

<mark>sizes = [3, 4, 6, 2] # an array of a number of splits</mark>

<mark>labels = ["A", "B", "C", "D"] # this array must be equal to the sizes array</mark>

<mark>plt.pie(sizes, labels = labels)</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

4) *adding descriptions to the graphs*

<mark>sizes = [3, 4, 6, 2] # an array of a number of splits</mark>

<mark>plt.pie(autopct = "%.2f") # shows the percentage of each part inside the split part</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

In the case of autopct, we can either pass a function that calculates the required value for us and then displays it or choose a percentage value by giving "%.nf" (n - denotes how many decimal values to show after the point eg:- 2f = 2 decimal values (1.86, 2,89 etc)).

5) *highlight certain part*

<mark>sizes = [3, 4, 6, 2] # an array of a number of splits</mark>

<mark>explode = [0.1, 0, 0, 0] # this array must be equal to the sizes array. Secondly, the values in the array represent which part needs to be more highlighted. In most cases, values less than 0.5 will be enough.</mark>

<mark>plt.pie(sizes, explode = explode)</mark>

<mark>plt.axis("equal") # makes it a perfect circle (optional)</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>
