{"id":26343,"date":"2021-12-17T08:43:09","date_gmt":"2021-12-17T03:13:09","guid":{"rendered":"https:\/\/python-programs.com\/?p=26343"},"modified":"2021-12-17T08:43:09","modified_gmt":"2021-12-17T03:13:09","slug":"in-python-how-can-you-plot-and-customize-a-pie-chart","status":"publish","type":"post","link":"https:\/\/python-programs.com\/in-python-how-can-you-plot-and-customize-a-pie-chart\/","title":{"rendered":"In Python, How can you Plot and Customize a Pie Chart?"},"content":{"rendered":"

A pie chart is a circular statistical picture graph\u00a0divided into slices to show numerical proportions. The arc length of each slice in a pie chart is proportionate to the quantity it represents.<\/p>\n

The area of the wedge is defined by the length of the wedge’s arc. The area of a wedge represents the percentage of that part of the data in relation to the entire data set. Pie charts are widely used in corporate presentations to provide a brief review of topics such as sales, operations, survey data, and resources.<\/p>\n

Pie charts are a common technique to display poll results.<\/p>\n

Creating data<\/h4>\n
# Give some random list(fruits) as static input and store it in a variable.\r\nfruit_lst = [\"Apple\", \"mango\", \"banana\", \"orange\", \"grapes\"]\r\n# Give the percentage list as static input and store it in another variable.\r\ngvn_percentges = [20, 15, 40, 10, 15]\r\n<\/pre>\n

How to Create a Pie Chart?<\/h4>\n

Matplotlib will be used to create a Pie-Chart.<\/p>\n

In its pyplot module, the Matplotlib API offers a pie() method that generates a pie chart based on the data in an array.<\/p>\n

Syntax:<\/strong><\/p>\n

matplotlib.pyplot.pie(data, explode=None, labels=None, colors=None, \r\nautopct=None, shadow=False)<\/pre>\n

Parameters<\/strong><\/p>\n

data:<\/strong> The array of data values to be plotted is represented by data, and the fractional area of each slice is represented by data\/sum (data). If sum(data)<1 returns the fractional area directly, the resulting pie will have an empty wedge of size 1-sum (data).<\/p>\n

labels:<\/strong> It is a list of string sequences that sets the label of each wedge.<\/p>\n

colour:<\/strong> The colour attribute is used to give the colour of the wedge.<\/p>\n

autopct: <\/strong>This is a string that is used to name each wedge with its numerical value.<\/p>\n

shadow:<\/strong> The shadow is utilised to generate the shadow of the wedge.<\/p>\n

To create a basic Pie-chart, we need labels and the values that go with those labels.<\/p>\n

Example<\/strong><\/p>\n

Approach:<\/strong><\/p>\n