0
0
Matplotlibdata~30 mins

Pie chart color customization in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Pie chart color customization
📖 Scenario: You are working with sales data for different fruits in a small grocery store. You want to show the sales distribution using a pie chart. To make the chart clearer and more attractive, you want to customize the colors of each slice.
🎯 Goal: Create a pie chart that shows the sales of fruits with custom colors for each fruit slice.
📋 What You'll Learn
Create a dictionary called fruit_sales with exact fruit names and sales numbers.
Create a list called colors with exact color names matching the fruits order.
Use matplotlib's plt.pie() function with the colors parameter to customize slice colors.
Print the pie chart with a title 'Fruit Sales Distribution'.
💡 Why This Matters
🌍 Real World
Pie charts are often used in business to show parts of a whole, like sales distribution among products.
💼 Career
Data analysts and scientists use pie charts to communicate data insights clearly to stakeholders.
Progress0 / 4 steps
1
Create the fruit sales data
Create a dictionary called fruit_sales with these exact entries: 'Apples': 30, 'Bananas': 15, 'Cherries': 45, 'Dates': 10.
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary with keys as fruit names and values as sales numbers.

2
Create the colors list
Create a list called colors with these exact color names in order: 'red', 'yellow', 'pink', 'brown'.
Matplotlib
Need a hint?

Use square brackets [] to create a list of color names as strings.

3
Create the pie chart with custom colors
Import matplotlib.pyplot as plt. Use plt.pie() with fruit_sales.values() as data and colors=colors to set slice colors. Add labels using fruit_sales.keys(). Add a title 'Fruit Sales Distribution' using plt.title().
Matplotlib
Need a hint?

Remember to import matplotlib.pyplot as plt first. Use the colors parameter inside plt.pie() to customize colors.

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

Use plt.show() to make the pie chart appear on the screen.