• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Using Matplotlib and Seaborn to Create Pie Chart in Python

Using Matplotlib and Seaborn to Create Pie Chart in Python

January 12, 2022 Leave a Comment

Using Matplotlib and Seaborn, you can create a pie chart in your Python code.

Seaborn is a fantastic statistical data visualization package, but does not give us the ability to create a pie chart. However, we can create a pie chart using Matplotlib and add a Seaborn color palette.

We can create a “Seaborn” Pie Chart very easily with the following Python code:

import matplotlib.pyplot as plt
import seaborn as sns

data = [25,50,15,45]
labels = ["West", "East", "South", "North"]

#Read in Seaborn color palette
colors = sns.color_palette('hls')[0:4]

#Create pie chart with Matplotlib
plt.pie(data, labels = labels, colors = colors, autopct='%1.1f%%')
plt.show()

Here is the pie chart from the code above:

seaborn pie chart

Using Different Seaborn Color Palettes in Matplotlib Pie Charts

When visualizing data, the ability to create and view pie charts is very useful. When using Python to visualize data, the Seaborn package is great, but doesn’t give us the ability to create a pie chart. Matplotlib on the other hand can create pie charts very easily.

Seaborn has wonderful color palettes, and with these color palettes, we can create beautiful “Seaborn” pie charts.

Let’s take the same data from above.

For example, if we want to create a pie chart in Python using the “hls” color space, we just need to pass ‘hls’ to the Seaborn color_palette() function.

import matplotlib.pyplot as plt
import seaborn as sns

data = [25,50,15,45]
labels = ["West", "East", "South", "North"]

#Read in Seaborn color palette
colors = sns.color_palette('hls')[0:4]

#Create pie chart with Matplotlib
plt.pie(data, labels = labels, colors = colors, autopct='%1.1f%%')
plt.show()

Here’s the pie chart with the color scheme using the “hls” color space:

seaborn pie chart hls

If we want to use the “Paired” color palette, we just need to pass “Paired” to the Seaborn color_palette() function.

import matplotlib.pyplot as plt
import seaborn as sns

data = [25,50,15,45]
labels = ["West", "East", "South", "North"]

#Read in Seaborn color palette
colors = sns.color_palette('Paired')[0:4]

#Create pie chart with Matplotlib
plt.pie(data, labels = labels, colors = colors, autopct='%1.1f%%')
plt.show()

Here’s the pie chart with the color scheme using the “Paired” color palette:

seaborn pie chart paired

Hopefully, this article has been helpful for you to learn how to use Matplotlib and Seaborn to create a pie chart in your Python code.

Other Articles You'll Also Like:

  • 1.  Set Widths of Columns in Word Document Table with python-docx
  • 2.  Using Python to Find Closest Value in List
  • 3.  Using Python to Find Minimum Value in List
  • 4.  Truncate String in Python with Slicing
  • 5.  How to Slice a Dictionary in Python
  • 6.  How to Write Excel File to AWS S3 Bucket Using Python
  • 7.  Check if File Exists in AWS S3 Bucket Using Python
  • 8.  Zip Two Lists in Python
  • 9.  Python Check if Object Has Attribute
  • 10.  Python turtle Colors – How to Color and Fill Shapes with turtle Module

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy