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 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 ON BOTH SIDES FOR EASY USE BY ALL CHEFS.
  • DURABLE RUST-RESISTANT STAINLESS STEEL FOR LONG-LASTING PERFORMANCE.
  • ERGONOMIC HANDLE ENSURES A COMFORTABLE GRIP EVERY TIME.
BUY & SAVE
$7.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
2 Vaikby Foot Measurement Device, Shoe Sizer Measuring Devices Ruler Sizer for Kids Adults, Buy Kids Shoes Online Simply with a Foot Measuring Device

Vaikby Foot Measurement Device, Shoe Sizer Measuring Devices Ruler Sizer for Kids Adults, Buy Kids Shoes Online Simply with a Foot Measuring Device

  • ACCURATE SIZING MADE EASY: US SIZE PRINTED FOR QUICK, CLEAR MEASUREMENTS.
  • PERFECT FOR KIDS & ADULTS: INCLUDES A TAPE FOR HARD-TO-FIT CHILDREN'S SHOES.
  • PORTABLE & CONVENIENT: COMES WITH A RETRACTABLE BAG FOR EASY STORAGE.
BUY & SAVE
$8.99
Vaikby Foot Measurement Device, Shoe Sizer Measuring Devices Ruler Sizer for Kids Adults, Buy Kids Shoes Online Simply with a Foot Measuring Device
3 BQWanFA Kids Foot Measuring Device Shoe Sizer for Infants and Children Accurate Foot Length Measurement Tool High Quality ABS Plastic Clear Markings US Standard Shoe Size Chart

BQWanFA Kids Foot Measuring Device Shoe Sizer for Infants and Children Accurate Foot Length Measurement Tool High Quality ABS Plastic Clear Markings US Standard Shoe Size Chart

  • ACCURATE SIZING ELIMINATES THE HASSLE OF BUYING WRONG SHOE SIZES.
  • A CHERISHED KEEPSAKE TO TRACK YOUR CHILD'S GROWTH OVER TIME.
  • DURABLE DESIGN ENSURES RELIABILITY THROUGH RAPID GROWTH PHASES.
BUY & SAVE
$8.59
BQWanFA Kids Foot Measuring Device Shoe Sizer for Infants and Children Accurate Foot Length Measurement Tool High Quality ABS Plastic Clear Markings US Standard Shoe Size Chart
4 Talisman Designs Pie Top Cutter | 10-Inch | Red | Pie Crust Cutter | Pie Decorating Tools | Pie Pastry Baking Accessories | Stencil Crust Cutout

Talisman Designs Pie Top Cutter | 10-Inch | Red | Pie Crust Cutter | Pie Decorating Tools | Pie Pastry Baking Accessories | Stencil Crust Cutout

  • IMPRESS GUESTS WITH STUNNING PIE CRUST DESIGNS EFFORTLESSLY!
  • COMPACT & SEMI-CIRCLE DESIGN FOR EASY STORAGE SOLUTIONS!
  • DURABLE, BPA-FREE MATERIALS FOR SAFE, SIMPLE CLEANUP!
BUY & SAVE
$10.50
Talisman Designs Pie Top Cutter | 10-Inch | Red | Pie Crust Cutter | Pie Decorating Tools | Pie Pastry Baking Accessories | Stencil Crust Cutout
5 Fox Run Pie Top Cutters and Decorating Kit, 11-Piece Set

Fox Run Pie Top Cutters and Decorating Kit, 11-Piece Set

  • CREATE STUNNING PIES WITH 11 DURABLE, FOOD-GRADE TOOLS INCLUDED!

  • CUSTOMIZE PIE TOPS EASILY WITH VERSATILE CUTTERS AND DECORATIVE ROLLER.

  • TRUSTED BRAND FOR 50+ YEARS, PERFECT FOR ALL YOUR BAKING OCCASIONS!

BUY & SAVE
$15.69
Fox Run Pie Top Cutters and Decorating Kit, 11-Piece Set
6 Hushee 5 Pcs Pie and Cake Marker Aluminum Alloy Guideline and Portion Divider Cake Cutter Cut Silver Pie Slice Cutter Baking Tools Kitchen Accessories Cook Supplies for Pizza (6,7,8,10,12 Cut)

Hushee 5 Pcs Pie and Cake Marker Aluminum Alloy Guideline and Portion Divider Cake Cutter Cut Silver Pie Slice Cutter Baking Tools Kitchen Accessories Cook Supplies for Pizza (6,7,8,10,12 Cut)

  • FIVE PIE MARKERS FOR PERFECT SLICES-IDEAL FOR ANY HOME OR PRO CHEF.
  • DURABLE ALUMINUM ALLOY CONSTRUCTION ENSURES LONG-LASTING RELIABILITY.
  • EASY-TO-USE DESIGN GUARANTEES PRECISE CUTTING FOR ANY DESSERT!
BUY & SAVE
$29.59
Hushee 5 Pcs Pie and Cake Marker Aluminum Alloy Guideline and Portion Divider Cake Cutter Cut Silver Pie Slice Cutter Baking Tools Kitchen Accessories Cook Supplies for Pizza (6,7,8,10,12 Cut)
7 PEMUISE Foot Measuring Device Shoe Sizer for Baby Kid Shoe Feet Measuring Ruler Sizer for Kids Adults Toddler Foot Measure

PEMUISE Foot Measuring Device Shoe Sizer for Baby Kid Shoe Feet Measuring Ruler Sizer for Kids Adults Toddler Foot Measure

  • ACCURATE SIZING: ENSURE PERFECT SHOE FIT EVERY TIME FOR KIDS AND ADULTS.

  • USER-FRIENDLY: SIMPLIFIES ONLINE SHOE SHOPPING FOR HASSLE-FREE EXPERIENCES.

  • DURABLE & SAFE: MADE FROM HIGH-QUALITY, LIGHTWEIGHT MATERIALS FOR KIDS.

BUY & SAVE
$9.49
PEMUISE Foot Measuring Device Shoe Sizer for Baby Kid Shoe Feet Measuring Ruler Sizer for Kids Adults Toddler Foot Measure
8 Talisman Designs Pastry Wheel Pie Crust Decorator | Pie Crust Wheel | Pie Crust Decorating Tools | Easy to Use Pastry Wheel | Pie Decorating Tools & Gadgets | Pie Crust Embosser

Talisman Designs Pastry Wheel Pie Crust Decorator | Pie Crust Wheel | Pie Crust Decorating Tools | Easy to Use Pastry Wheel | Pie Decorating Tools & Gadgets | Pie Crust Embosser

  • CREATE STUNNING, BAKERY-STYLE PIES WITH EFFORTLESS, PROFESSIONAL EDGES!
  • VERSATILE DESIGN FOR PERFECT SINGLE OR DOUBLE CRUSTS EVERY TIME.
  • QUICK CLEANUP WITH DURABLE, BPA-FREE, DISHWASHER-SAFE MATERIALS!
BUY & SAVE
$17.50 $18.95
Save 8%
Talisman Designs Pastry Wheel Pie Crust Decorator | Pie Crust Wheel | Pie Crust Decorating Tools | Easy to Use Pastry Wheel | Pie Decorating Tools & Gadgets | Pie Crust Embosser
9 Foot Measurement Device for Kids & Adults | Accurate Shoe Sizer Measuring Tool with High-Contrast Scale & Bonus Soft Tape Ruler, US EU Sizes for Home Store Use

Foot Measurement Device for Kids & Adults | Accurate Shoe Sizer Measuring Tool with High-Contrast Scale & Bonus Soft Tape Ruler, US EU Sizes for Home Store Use

  • ⚫️ ALL-IN-ONE FOOT SIZER FITS EVERYONE FROM BABIES TO ADULTS.
  • 📏 INCLUDES SOFT TAPE FOR MEASURING WIDTH AND INSTEP FOR PERFECT FIT.
  • 🚪 ULTRA-PORTABLE DESIGN MAKES SHOE FITTING CONVENIENT ANYWHERE.
BUY & SAVE
$12.99 $13.99
Save 7%
Foot Measurement Device for Kids & Adults | Accurate Shoe Sizer Measuring Tool with High-Contrast Scale & Bonus Soft Tape Ruler, US EU Sizes for Home Store Use
10 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 PIE EDGES WITH EASY-TO-USE DECORATIVE STAMPS!
  • IMPRESS GUESTS WITH PROFESSIONAL-LOOKING, PERFECTLY SEALED CRUSTS.
  • DURABLE, DISHWASHER-SAFE DESIGN FOR EFFORTLESS BAKING AND CLEANUP!
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
+
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.