How to Plot a Pie Chart in Python ?

Introduction

You can easily plot a pie chart in Python using Matplotlib.

Examples with matplotlib

Here’s a simple example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import matplotlib.pyplot as plt

# Data
labels = ['Apples', 'Bananas', 'Cherries', 'Dates']
sizes = [30, 20, 35, 15]
colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99']
explode = (0.05, 0, 0, 0)  # Slightly separate the first slice

# Create pie chart
plt.figure(figsize=(6,6))
plt.pie(
    sizes,
    labels=labels,
    colors=colors,
    explode=explode,
    autopct='%1.1f%%',  # display percentages with 1 decimal
    startangle=90,       # rotate so first slice starts at 90°
    shadow=True
)

plt.title("Fruit Distribution")
plt.show()

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Explanation:

  • labels: Names of each category.
  • sizes: Values (must sum to 100 if you want percentages, but not required).
  • colors: Optional — defines the slice colors.
  • explode: Optional — separates slices visually.
  • autopct: Shows percentage values inside the chart.
  • startangle: Rotates the chart for better orientation.

Exploded Pie Chart with Percent + Category Labels

Great for showing composition clearly.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import matplotlib.pyplot as plt

# Data
sizes = [40, 25, 20, 10, 5]
labels = ['Python', 'JavaScript', 'C++', 'Java', 'Other']
colors = plt.cm.viridis([0.1, 0.3, 0.5, 0.7, 0.9])
explode = [0.1 if s == max(sizes) else 0 for s in sizes]

# Plot
plt.figure(figsize=(7,7))
wedges, texts, autotexts = plt.pie(
    sizes,
    labels=labels,
    autopct=lambda p: f'{p:.1f}%\n({int(p*sum(sizes)/100)})',
    colors=colors,
    explode=explode,
    startangle=140,
    textprops={'color':"w", 'fontsize':12},
    shadow=True
)

plt.setp(autotexts, size=10, weight="bold")
plt.title("Programming Language Popularity", fontsize=14)
plt.show()

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Tip: autopct with a custom lambda lets you display both percentage and raw count.

Donut Chart (Pie Chart with a Hole)

Donuts look modern and are great when space is limited.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import matplotlib.pyplot as plt

sizes = [50, 30, 15, 5]
labels = ['North America', 'Europe', 'Asia', 'Other']

fig, ax = plt.subplots(figsize=(6,6))
wedges, texts, autotexts = ax.pie(
    sizes,
    labels=labels,
    autopct='%1.1f%%',
    startangle=90,
    wedgeprops={'width':0.4, 'edgecolor':'white'}
)

ax.set_title("Market Share by Region")
plt.show()

wedgeprops={'width':0.4} turns it into a donut chart.

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Nested (Double) Donut Chart

Perfect for comparing two levels of data — e.g., regions and subregions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import matplotlib.pyplot as plt

outer_sizes = [50, 30, 20]
outer_labels = ['Americas', 'Europe', 'Asia']
inner_sizes = [25, 15, 10, 10, 8, 12, 5, 3, 12]
inner_labels = ['USA', 'Canada', 'Brazil', 'UK', 'France', 'Germany', 'China', 'India', 'Japan']

fig, ax = plt.subplots(figsize=(7,7))
ax.pie(outer_sizes, radius=1, labels=outer_labels, 
       wedgeprops=dict(width=0.3, edgecolor='white'))
ax.pie(inner_sizes, radius=0.7, labels=inner_labels, 
       wedgeprops=dict(width=0.3, edgecolor='white'))

ax.set(aspect="equal", title='Global Sales by Region and Country')
plt.show()

The outer ring shows regions, the inner ring shows countries within each region.

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Pie Chart with Dynamic Colormap

Adds variety automatically with color maps.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import matplotlib.pyplot as plt
import numpy as np

categories = ['A','B','C','D','E','F','G']
values = np.random.randint(10, 50, size=len(categories))

plt.figure(figsize=(7,7))
plt.pie(values, labels=categories, 
        colors=plt.cm.plasma(np.linspace(0, 1, len(categories))),
        autopct='%1.1f%%', startangle=90)
plt.title('Dynamic Colors with Colormap')
plt.show()

Using

1
plt.cm.<colormap>

automatically produces aesthetic color gradients.

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Examples with Pandas

If you already have a DataFrame, you can directly plot a pie chart:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import pandas as pd
import matplotlib.pyplot as plt

data = {'Fruit': ['Apple', 'Banana', 'Cherry', 'Date'],
        'Count': [30, 20, 35, 15]}
df = pd.DataFrame(data)

df.set_index('Fruit')['Count'].plot(kind='pie', autopct='%1.1f%%', figsize=(6,6))
plt.ylabel('')  # remove y-label
plt.title('Fruit Distribution')
plt.show()

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Pie Chart from a Pandas DataFrame

Useful for real data pipelines.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({
    'Category': ['Energy', 'Transport', 'Agriculture', 'Industry', 'Residential'],
    'Emissions': [35, 25, 20, 15, 5]
})

df.set_index('Category')['Emissions'].plot(
    kind='pie', 
    autopct='%1.1f%%',
    cmap='coolwarm',
    figsize=(6,6),
    title='Global CO₂ Emissions by Sector'
)
plt.ylabel('')
plt.show()

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Can Seaborn Be Used to Create Pie Charts?

Seaborn is not designed for pie charts, and using it for that purpose is not worth it.

Seaborn’s Design Philosophy

Seaborn is built on top of Matplotlib, but it focuses on statistical visualizations — e.g.:

  • distributions (sns.histplot, sns.kdeplot)
  • categorical comparisons (sns.barplot, sns.boxplot)
  • relationships (sns.scatterplot, sns.lineplot)
  • matrices (sns.heatmap)

It intentionally does not implement pie charts, because:

  • Pie charts are considered less effective for comparing magnitudes precisely.
  • Bar charts or horizontal bars communicate proportions more clearly.

Alternative: Use Seaborn’s Style with Matplotlib

You can still make your pie chart look better using Seaborn’s aesthetics:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import matplotlib.pyplot as plt
import seaborn as sns

sns.set_theme(style="whitegrid")  # apply seaborn style

sizes = [40, 25, 20, 15]
labels = ['A', 'B', 'C', 'D']

plt.figure(figsize=(6,6))
plt.pie(
    sizes,
    labels=labels,
    autopct='%1.1f%%',
    startangle=90,
    colors=sns.color_palette("pastel")
)
plt.title("Pie Chart with Seaborn Style")
plt.show()

This combines Seaborn’s clean color palettes and Matplotlib’s pie chart rendering.

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Better Alternatives to Pie Charts in Seaborn

If you want to show proportions more effectively:

  • sns.barplot() → for comparing parts to a whole
  • sns.histplot() with multiple='fill' → for stacked percentage bars
  • sns.countplot() → for categorical counts with easy comparison
  • sns.violinplot() / sns.boxplot() → for distributions

Example — a bar chart alternative to a pie chart:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

data = pd.DataFrame({
    "Category": ["A", "B", "C", "D"],
    "Value": [40, 25, 20, 15]
})

sns.barplot(data=data, x="Category", y="Value", palette="pastel")
plt.title("Proportion Comparison (Better than Pie Chart)")
plt.show()

How to Plot a Pie Chart in Python ?
How to Plot a Pie Chart in Python ?

Summary

Question Answer
Does Seaborn have a pieplot()? No
Can Seaborn improve Matplotlib pie chart style? Yes (via palettes and themes)
Is it worth using Seaborn just for pie charts? Not really
Better Seaborn alternatives? barplot, countplot, histplot

References

Links Site
https://matplotlib.org/stable/gallery/pie_and_polar_charts/pie_features.html Matplotlib – Pie Chart Features Gallery
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html Matplotlib – pyplot.pie() Official Documentation
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.html Pandas – DataFrame.plot() Method (for pie charts)
Image

of