0
0
Matplotlibdata~30 mins

Basic pie chart with plt.pie in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic pie chart with plt.pie
📖 Scenario: You work in a small bakery and want to show which types of bread sell the most. You have the sales numbers for different bread types.
🎯 Goal: Create a pie chart using plt.pie to show the sales distribution of bread types.
📋 What You'll Learn
Create a dictionary called bread_sales with exact keys and values
Create a list called labels from the dictionary keys
Create a list called sizes from the dictionary values
Use plt.pie with sizes and labels to make the pie chart
Display the pie chart with plt.show()
💡 Why This Matters
🌍 Real World
Pie charts help businesses quickly see how parts contribute to a whole, like sales of different products.
💼 Career
Data analysts and scientists often use pie charts to present categorical data visually to stakeholders.
Progress0 / 4 steps
1
Create the bread sales data
Create a dictionary called bread_sales with these exact entries: 'White': 40, 'Wheat': 25, 'Rye': 20, 'Sourdough': 15.
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary with the given keys and values.

2
Prepare labels and sizes lists
Create a list called labels from the keys of bread_sales and a list called sizes from the values of bread_sales.
Matplotlib
Need a hint?

Use list() with bread_sales.keys() and bread_sales.values() to get the lists.

3
Create the pie chart
Import matplotlib.pyplot as plt and use plt.pie with sizes and labels to create the pie chart.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt and then plt.pie() with the right arguments.

4
Show the pie chart
Use plt.show() to display the pie chart.
Matplotlib
Need a hint?

Call plt.show() to open the pie chart window.