Python | Separating Each Slice in Pie Plot

Here, we are going to learn about the separating each slice in pie plot and its Python implementation.
Submitted by Anuj Singh, on July 19, 2020

A pie plot or a pie chart is a circular statistical graphic technique, in which a circle is divided into slices with respect to numerical proportion. In a pie chart, the arc length, central angle, and area of each slice, is proportional to the quantity it represents. The sum of the total is always equal to 100 percent in the basic pie chart.

The name pie in the pie plot is derived for its resemblance to a pie that has been sliced. Pie charts are very widely used in the different types of projects and business world. Matplotlib has a defined function in matplotlib.pyplot.pie() for plotting a pie chart. In this tutorial, we are going to separate all the slices of the pie chart for different distances. The following example is an illustration of the same.

distance = 0.2
separate = (distance, distance, distance, distance, distance, distance)
matplotlib.pyplot.pie(sizes, labels=labels, explode=saperate, autopct='%1.1f%%')
Python | Separating Each Slice in Pie Plot (1)

Python | Separating Each Slice in Pie Plot (2)

Python | Separating Each Slice in Pie Plot (3)

Python code for separating each slice in pie plot

# Data Visualization using Python
# Separating each Slice in Pie Plot

import matplotlib.pyplot as plt

# Pie chart, where the slices will be ordered 
# and plotted counter-clockwise:
labels = 'A', 'B', 'C', 'D', 'E', 'F'
sizes = [15, 20, 10, 17, 1, 37]

# Illustration 1
distance = 0.2
separate = (distance, distance, distance, distance, distance, distance)
plt.figure()
plt.pie(sizes, labels=labels, explode=separate, autopct='%1.1f%%')
# Equal aspect ratio ensures that 
# pie is drawn as a circle.
plt.axis('equal')  
plt.title('saperation diatance = 0.4')
plt.show()

# Illustration 2
distance = 0.1
separate = (distance, distance, distance, distance, distance, distance)
plt.figure()
plt.pie(sizes, labels=labels, explode=separate, autopct='%1.1f%%')
# Equal aspect ratio ensures that 
# pie is drawn as a circle.
plt.axis('equal')  
plt.title('saperation diatance = 0.2')
plt.show()

# Illustration 3
distance = 0.4
separate = (distance, distance, distance, distance, distance, distance)
plt.figure()
plt.pie(sizes, labels=labels, explode=separate, autopct='%1.1f%%')
# Equal aspect ratio ensures that 
# pie is drawn as a circle.
plt.axis('equal')  
plt.title('saperation diatance = 0.8')
plt.show()

Output:

Output is as figure


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.