Skip to main content
TopMiniSite

Back to all posts

How to Create A Pie Chart In Matplotlib?

Published on
5 min read
How to Create A Pie Chart In Matplotlib? image

Best Tools to Create Stunning Pie Charts to Buy in October 2025

1 Awoeorsty Foot Reflexology Chart Socks with Massage Tools - Acupressure Socks Kit for Foot Pain Relief & Home Relaxation

Awoeorsty Foot Reflexology Chart Socks with Massage Tools - Acupressure Socks Kit for Foot Pain Relief & Home Relaxation

  • BOOST WELLNESS: REFLEXOLOGY SOCKS ENHANCE HEALTH THROUGH ACUPRESSURE.

  • RELAX AND REJUVENATE: PROMOTE CIRCULATION AND REDUCE STRESS EFFORTLESSLY!

  • QUALITY COMFORT: DURABLE, SOFT MATERIALS ENSURE A PLEASANT MASSAGE EXPERIENCE.

BUY & SAVE
$4.99
Awoeorsty Foot Reflexology Chart Socks with Massage Tools - Acupressure Socks Kit for Foot Pain Relief & Home Relaxation
2 Talisman Designs Pie Crust Decorating Tools | Pastry Wheel Cutter | Set of 1

Talisman Designs Pie Crust Decorating Tools | Pastry Wheel Cutter | Set of 1

  • EFFORTLESSLY CUT PERFECT LATTICE STRIPS EVERY TIME WITH EASE!
  • VERSATILE TOOL FOR PASTRIES, PASTA, AND FONDANT-BAKE LIKE A PRO!
  • DURABLE, DISHWASHER-SAFE DESIGN SAVES TIME FOR YOUR GUESTS!
BUY & SAVE
$12.00
Talisman Designs Pie Crust Decorating Tools | Pastry Wheel Cutter | Set of 1
3 Sentence Flip Charts, 80 Double Sided Cards 40 Sentences, Learn Parts of Speech Who/What/Where Sentence Building Freestanding Flip Chart Educational Tool for Preschool Kindergarten 1st 2nd Grade

Sentence Flip Charts, 80 Double Sided Cards 40 Sentences, Learn Parts of Speech Who/What/Where Sentence Building Freestanding Flip Chart Educational Tool for Preschool Kindergarten 1st 2nd Grade

  • ENHANCE WRITING SKILLS WITH INTERACTIVE, DOUBLE-SIDED FLASHCARDS!

  • FREESTANDING DESIGN PROMOTES INDEPENDENT LEARNING ANYWHERE!

  • SAFE, DURABLE MATERIALS ENSURE LONG-LASTING EDUCATIONAL FUN!

BUY & SAVE
$7.99
Sentence Flip Charts, 80 Double Sided Cards 40 Sentences, Learn Parts of Speech Who/What/Where Sentence Building Freestanding Flip Chart Educational Tool for Preschool Kindergarten 1st 2nd Grade
4 HOSALA (3in - 3Pcs) Ohm's Law Sticker Ohm's Law Pie Chart Physics Sticker Electricity Explained Science Gift Electrician Journeyman Decoration Laptop Toolbox Vehicles Helmet Bumper

HOSALA (3in - 3Pcs) Ohm's Law Sticker Ohm's Law Pie Chart Physics Sticker Electricity Explained Science Gift Electrician Journeyman Decoration Laptop Toolbox Vehicles Helmet Bumper

  • VERSATILE USE ON ANY SMOOTH SURFACE, FROM LAPTOPS TO WATER BOTTLES!
  • LONG-LASTING DESIGN ENSURES VIBRANT LOOK FOR YEARS TO COME.
  • PACK OF 3 IDENTICAL STICKERS - SHARE WITH FRIENDS OR MIX UP!
BUY & SAVE
$6.99
HOSALA (3in - 3Pcs) Ohm's Law Sticker Ohm's Law Pie Chart Physics Sticker Electricity Explained Science Gift Electrician Journeyman Decoration Laptop Toolbox Vehicles Helmet Bumper
5 Good Charts Workbook: Tips, Tools, and Exercises for Making Better Data Visualizations

Good Charts Workbook: Tips, Tools, and Exercises for Making Better Data Visualizations

BUY & SAVE
$17.58 $35.00
Save 50%
Good Charts Workbook: Tips, Tools, and Exercises for Making Better Data Visualizations
6 Talisman Designs Pastry Stamps | Set of 3 | Pie Crust Embosser | Pie Decorating Tools & Gadgets | Pie Baking Crust Cutters | Cute & Functional Kitchen Supplies

Talisman Designs Pastry Stamps | Set of 3 | Pie Crust Embosser | Pie Decorating Tools & Gadgets | Pie Baking Crust Cutters | Cute & Functional Kitchen Supplies

  • CREATE STUNNING PIES WITH PROFESSIONAL-LOOKING DECORATIVE EDGES.
  • EASY-TO-USE STAMPS MAKE BAKING FUN AND ELEVATE EVERY OCCASION.
  • DURABLE, BPA-FREE DESIGN ENSURES SAFE, HASSLE-FREE BAKING EVERY TIME.
BUY & SAVE
$9.95 $11.00
Save 10%
Talisman Designs Pastry Stamps | Set of 3 | Pie Crust Embosser | Pie Decorating Tools & Gadgets | Pie Baking Crust Cutters | Cute & Functional Kitchen Supplies
7 Reflexology Socks with Tools Set, Acupressure Pressure Point Socks, Foot Relief and Acupuncture with Trigger Point Massage Reflexology Chart Socks and Tool for Men and Women

Reflexology Socks with Tools Set, Acupressure Pressure Point Socks, Foot Relief and Acupuncture with Trigger Point Massage Reflexology Chart Socks and Tool for Men and Women

  • HOLISTIC HEALING: ENHANCE BODY HEALTH WITH REFLEXOLOGY SOCK BENEFITS!

  • TARGET ACUPOINTS: PRECISION MASSAGE TOOLS FOR OPTIMAL RELAXATION.

  • PERFECT GIFT: IDEAL CHOICE FOR PAIN RELIEF AND OVERALL WELLNESS!

BUY & SAVE
$9.90
Reflexology Socks with Tools Set, Acupressure Pressure Point Socks, Foot Relief and Acupuncture with Trigger Point Massage Reflexology Chart Socks and Tool for Men and Women
8 Orblue Pie Server, Essential Kitchen Tool, Serrated on Both Sides, Great for Right or Left Handed Chef, Stainless Steel Flatware, Cake Cutter, Dark Green

Orblue Pie Server, Essential Kitchen Tool, Serrated on Both Sides, Great for Right or Left Handed Chef, Stainless Steel Flatware, Cake Cutter, Dark Green

  • SERRATED EDGES FOR EFFORTLESS SLICING BY ANY CHEF, LEFT OR RIGHT!
  • DURABLE RUST-RESISTANT STAINLESS STEEL ENSURES LONG-LASTING USE.
  • COMFORTABLE ERGONOMIC HANDLE FOR A SECURE, EASY GRIP DURING USE.
BUY & SAVE
$8.99
Orblue Pie Server, Essential Kitchen Tool, Serrated on Both Sides, Great for Right or Left Handed Chef, Stainless Steel Flatware, Cake Cutter, Dark Green
9 FYSUIMU 24Pcs I Need Help Mini Flip Chart Signs 3 Colors Self Assessment Cards Behavior Management Tool for Student Teacher School Classroom Learning Activity Supplies

FYSUIMU 24Pcs I Need Help Mini Flip Chart Signs 3 Colors Self Assessment Cards Behavior Management Tool for Student Teacher School Classroom Learning Activity Supplies

  • VERSATILE USE: 24 MINI FLIP CHARTS FOR CLASSROOMS & HOMESCHOOLING NEEDS.
  • VIBRANT & ENGAGING: BRIGHT COLORS BOOST SELF-ASSESSMENT & CONFIDENCE.
  • DURABLE & COMPACT: PREMIUM QUALITY CARDS ARE EASY TO HOLD, STORE, & SHARE.
BUY & SAVE
$9.99 $17.99
Save 44%
FYSUIMU 24Pcs I Need Help Mini Flip Chart Signs 3 Colors Self Assessment Cards Behavior Management Tool for Student Teacher School Classroom Learning Activity Supplies
10 Pastry Wheel Decorator and Cutter, 6Pcs Pie Wheel, Pastry Wheel Roll, Pie Crust Cutter, Pastry Cutters, Pies Cutters, Pizza Pastry Pie Lattice Cookie Biscuit Decoration, DIY Baking Cooking Tool

Pastry Wheel Decorator and Cutter, 6Pcs Pie Wheel, Pastry Wheel Roll, Pie Crust Cutter, Pastry Cutters, Pies Cutters, Pizza Pastry Pie Lattice Cookie Biscuit Decoration, DIY Baking Cooking Tool

  • ECO-FRIENDLY MATERIALS ENSURE SAFE BAKING FOR YOU AND YOUR FAMILY!

  • CREATE BEAUTIFUL BRAIDED PIE CRUSTS EFFORTLESSLY WITH EVERY ROLL!

  • VERSATILE 6-PIECE SET PERFECT FOR ALL YOUR BAKING NEEDS AND EASY TO CLEAN!

BUY & SAVE
$9.96
Pastry Wheel Decorator and Cutter, 6Pcs Pie Wheel, Pastry Wheel Roll, Pie Crust Cutter, Pastry Cutters, Pies Cutters, Pizza Pastry Pie Lattice Cookie Biscuit Decoration, DIY Baking Cooking Tool
+
ONE MORE?

To create a pie chart in Matplotlib, you can follow these steps:

  1. Import the required libraries: import matplotlib.pyplot as plt
  2. Prepare your data: labels = ['Label1', 'Label2', 'Label3', ...] # Labels for each section of the pie sizes = [size1, size2, size3, ...] # Sizes/proportions for each section
  3. Create the pie chart: plt.pie(sizes, labels=labels) Optionally, you can use additional parameters such as colors, explode, startangle, etc. to customize the appearance of the chart.
  4. Add a title and/or legend (if desired): plt.title('Title of the Pie Chart') plt.legend()
  5. Display the chart: plt.show()
  6. If you want to save the chart as an image file instead of displaying it, you can use: plt.savefig('chart.png')

That's it! By following these steps, you can create a pie chart using Matplotlib in Python. Remember to adjust the data and customize the chart as per your requirements.

How to remove the top and right spines from a plot in Matplotlib?

To remove the top and right spines from a plot in Matplotlib, you can use the spines attribute of the Axes object and set their visibility to False. Here's an example:

import matplotlib.pyplot as plt

Create a figure and an axes object

fig, ax = plt.subplots()

Generate some sample data

x = [0, 1, 2, 3, 4, 5] y = [0, 1, 4, 9, 16, 25]

Plot the data

ax.plot(x, y)

Remove the top and right spines

ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False)

Show the plot

plt.show()

In this example, we create a figure and an axes object using plt.subplots(). Then, we plot the data using ax.plot(x, y). Finally, we remove the top and right spines by setting their visibility to False using ax.spines['top'].set_visible(False) and ax.spines['right'].set_visible(False).

Running this code will display the plot with the top and right spines removed.

How to control axis tick labels in Matplotlib?

To control axis tick labels in Matplotlib, you can use the following methods:

  1. Customize the tick labels: plt.xticks() and plt.yticks() functions can be used to specify the positions and labels of the tick marks on the x-axis and y-axis, respectively. You can pass an array of values to these functions to set the positions of the tick marks. You can also pass a list of labels to set the corresponding tick labels.

Example 1: Changing x-axis tick labels to custom labels

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

plt.plot(x, y) plt.xticks(x, ['A', 'B', 'C', 'D', 'E'])

plt.show()

Example 2: Setting x-axis tick labels to specific positions

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

plt.plot(x, y) plt.xticks([1, 3, 5], ['Minimum', 'Average', 'Maximum'])

plt.show()

  1. Format the tick labels: You can use the plt.tick_params() function to customize various properties of the tick labels, such as font size, rotation, and alignment. You can set the labelsize parameter to specify the font size of the tick labels. You can set the rotation parameter to rotate the tick labels, and the ha (horizontal alignment) parameter to align them.

Example: Formatting x-axis tick labels

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

plt.plot(x, y) plt.xticks(fontsize=12, rotation=45, ha='right')

plt.show()

These methods allow you to control the appearance of tick labels on the x-axis and y-axis in Matplotlib. You can adjust them according to your specific requirements.

How to create a stacked bar chart in Matplotlib?

To create a stacked bar chart in Matplotlib, you can follow these steps:

  1. Import the necessary libraries:

import matplotlib.pyplot as plt import numpy as np

  1. Define the data for the chart. In this example, we will use three categories and their respective values:

categories = ['Category 1', 'Category 2', 'Category 3'] values1 = [10, 15, 12] values2 = [8, 12, 10]

  1. Compute the cumulative values for each category. This is required to create the stacked bars:

bottom_values1 = np.zeros(len(values1)) bottom_values2 = values1

  1. Create the bar chart using the bar function. Pass the x-coordinate (position of the bars), values, and bottom values for each category:

plt.bar(categories, values1, label='Value 1') plt.bar(categories, values2, bottom=bottom_values2, label='Value 2')

  1. Customize the chart by adding labels, legend, and title:

plt.xlabel('Categories') plt.ylabel('Values') plt.legend() plt.title('Stacked Bar Chart')

  1. Finally, display the chart:

plt.show()

Here's the complete code:

import matplotlib.pyplot as plt import numpy as np

categories = ['Category 1', 'Category 2', 'Category 3'] values1 = [10, 15, 12] values2 = [8, 12, 10]

bottom_values1 = np.zeros(len(values1)) bottom_values2 = values1

plt.bar(categories, values1, label='Value 1') plt.bar(categories, values2, bottom=bottom_values2, label='Value 2')

plt.xlabel('Categories') plt.ylabel('Values') plt.legend() plt.title('Stacked Bar Chart')

plt.show()

This will create a stacked bar chart with two values for each category.

How to create a polar plot in Matplotlib?

To create a polar plot in Matplotlib, you can follow these steps:

  1. Import the necessary libraries:

import numpy as np import matplotlib.pyplot as plt

  1. Define the data for the polar plot:

theta = np.linspace(0, 2*np.pi, 100) radius = np.abs(np.sin(5*theta))

  1. Create a polar plot using the plt.polar function:

plt.polar(theta, radius)

  1. Customize the plot by adding labels, title, or grid lines:

plt.xlabel("Theta") plt.ylabel("Radius") plt.title("Polar Plot") plt.grid(True)

  1. Show the polar plot using plt.show():

plt.show()

Here's an example of creating a simple polar plot with a sinusoidal curve:

import numpy as np import matplotlib.pyplot as plt

theta = np.linspace(0, 2*np.pi, 100) radius = np.abs(np.sin(5*theta))

plt.polar(theta, radius) plt.xlabel("Theta") plt.ylabel("Radius") plt.title("Polar Plot") plt.grid(True) plt.show()

This will display the polar plot with a sinusoidal curve. You can modify the data or customize the plot to suit your needs.