0
0
Matplotlibdata~30 mins

Donut chart variation in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Donut Chart Variation
📖 Scenario: You work at a bakery that sells different types of donuts. You want to show which donut flavors are most popular using a donut chart. This chart will help your team understand customer preferences visually.
🎯 Goal: Create a donut chart using matplotlib to display the sales distribution of donut flavors. You will start by setting up the sales data, then configure the chart style, create the donut chart, and finally display it.
📋 What You'll Learn
Use a dictionary called donut_sales with exact keys and values for donut flavors and their sales.
Create a variable called colors to hold a list of colors for the chart slices.
Use matplotlib.pyplot.pie to create a pie chart with a hole in the center to make it a donut chart.
Display the donut chart with labels and a legend.
💡 Why This Matters
🌍 Real World
Donut charts are useful to show parts of a whole in sales, survey results, or any category distribution in a visually appealing way.
💼 Career
Data analysts and scientists often use donut charts to communicate insights clearly to non-technical stakeholders.
Progress0 / 4 steps
1
Set up donut sales data
Create a dictionary called donut_sales with these exact entries: 'Glazed': 40, 'Chocolate': 35, 'Strawberry': 25.
Matplotlib
Need a hint?

Use curly braces {} to create the dictionary with keys as donut flavors and values as sales numbers.

2
Configure colors for the donut chart
Create a list called colors with these exact color strings: '#ff9999', '#66b3ff', '#99ff99'.
Matplotlib
Need a hint?

Colors are strings inside a list. Use square brackets [] and separate colors with commas.

3
Create the donut chart
Import matplotlib.pyplot as plt. Use plt.pie with donut_sales.values() for sizes, labels=donut_sales.keys(), colors=colors, and wedgeprops={{'width': 0.4}} to create a donut chart.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt at the top. The wedgeprops with {'width': 0.4} creates the donut hole.

4
Display the donut chart
Add plt.title("Donut Sales Distribution") to set the chart title. Then call plt.show() to display the chart.
Matplotlib
Need a hint?

Use plt.title() to add a title. plt.show() displays the chart window.