0
0
Matplotlibdata~30 mins

Exploding slices in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Exploding slices
📖 Scenario: You are preparing a pie chart to show the favorite fruits of a group of people. You want to highlight one fruit by pulling its slice out from the pie chart.
🎯 Goal: Create a pie chart with slices representing fruit counts. Then, explode the slice for the fruit with the highest count to make it stand out.
📋 What You'll Learn
Create a dictionary called fruit_counts with exact entries for fruits and their counts
Create a list called explode to control which slice is exploded
Use matplotlib.pyplot.pie() with the explode parameter to create the pie chart
Print the explode list to show which slice is exploded
💡 Why This Matters
🌍 Real World
Pie charts are used in reports and presentations to show parts of a whole. Exploding slices helps highlight important categories.
💼 Career
Data analysts and scientists often use pie charts to communicate data insights clearly and attractively.
Progress0 / 4 steps
1
Create the fruit counts dictionary
Create a dictionary called fruit_counts with these exact entries: 'Apple': 30, 'Banana': 15, 'Cherry': 45, 'Date': 10.
Matplotlib
Need a hint?

Use curly braces {} to create the dictionary with the exact fruit names and counts.

2
Create the explode list
Create a list called explode with four values, all set to 0 initially.
Matplotlib
Need a hint?

Create a list with four zeros to match the number of fruits.

3
Set explode for the largest slice
Find the index of the fruit with the highest count in fruit_counts and set the corresponding value in explode to 0.1.
Matplotlib
Need a hint?

Use max() to find the highest count and index() to find its position.

4
Create and display the pie chart
Import matplotlib.pyplot as plt. Use plt.pie() with fruit_counts.values() and explode=explode to create the pie chart. Use plt.show() to display it. Then print the explode list.
Matplotlib
Need a hint?

Use plt.pie() with labels and explode. Then call plt.show() to display the chart.