We can create a pie chart seaborn easily using pie() function of matplotlib and seaborn library. We can pass data and label in list format. In this article, We will create some sample data and create a self-explainable pie chart using these libraries.
pie chart seaborn ( Steps )-
In order to simplify the pie chart implementation, we will do it step by step. In the first step, we will import relevant libraries. Moving forward in the second step, We will create sample data. Also in the third step, we will finally plot the pie chart.
Step 1 : ( Import )-
These are necessary package for pie chart creation using seaborn and matplotlib.
import matplotlib.pyplot as plt import seaborn as sns
Step 2: Sample Data Creation –
We will create some dummy data in the form of a list to draw a pie chart in python matplotlib.
#Data data = [10, 20, 15, 39, 5,9] labels = ['Section 1', 'Section 2', 'Section 3', 'Section 4', 'Section 5','Section 6']
Step 3: Pie chart Implementation –
In this step, I will plot the pie chart using the same data. Firstly let’s run the below code. Here color_palette() function is important to set the colors.
colors = sns.color_palette('pastel')[0:6] #pie chart plt.pie(data, labels = labels, colors = colors, autopct='%.0f%%') plt.show()
Complete code –
When we combine the code from each step and run it together. We will get our pie chart.
import matplotlib.pyplot as plt import seaborn as sns #Data data = [10, 20, 15, 24, 5,9] labels = ['Section 1', 'Section 2', 'Section 3', 'Section 4', 'Section 5','Section 6'] #seaborn library colors = sns.color_palette('pastel')[0:6] #pie chart plt.pie(data, labels = labels, colors = colors, autopct='%.0f%%') plt.show()
This complete data and labels can be changed as per the business logic. You may directly use this article as a piece of the code base for your project or assignment. All we need to do is a basic level of modification as per our use case.
I hope you must have found this article informative. If you have any concerns related to this topic, please feel free to write back to us. You may either send an email or comment below in the comment box. Our Team will connect back as soon as possible.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.