0
0
Matplotlibdata~30 mins

Why color matters in visualization in Matplotlib - See It in Action

Choose your learning style9 modes available
Why Color Matters in Visualization
📖 Scenario: You are working as a data analyst for a local grocery store. You want to show the sales of different fruit types using a bar chart. You will learn how color can help make your chart easier to understand and more attractive.
🎯 Goal: Create a bar chart showing fruit sales with colors that help viewers quickly see which fruit sold the most and which sold the least.
📋 What You'll Learn
Create a dictionary with fruit names and their sales numbers.
Create a list of colors to use for each fruit bar.
Use matplotlib to plot a bar chart with the fruit names on the x-axis and sales on the y-axis.
Apply the colors list to the bars to highlight differences clearly.
Print the sales dictionary at the end.
💡 Why This Matters
🌍 Real World
Colors in charts help customers and managers quickly see important information, like which products sell best.
💼 Career
Data analysts and scientists use color in visualizations to make reports easier to understand and more persuasive.
Progress0 / 4 steps
1
Create the fruit sales data
Create a dictionary called fruit_sales with these exact entries: 'Apples': 50, 'Bananas': 30, 'Cherries': 20, 'Dates': 15, 'Elderberries': 5.
Matplotlib
Need a hint?

Use curly braces to create a dictionary. Each fruit name is a key and its sales number is the value.

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

Use square brackets to create a list. Put the color names as strings in the order matching the fruits.

3
Plot the bar chart with colors
Use matplotlib to plot a bar chart with fruit names on the x-axis and sales numbers on the y-axis. Use the colors list to color each bar. Use plt.bar(fruit_sales.keys(), fruit_sales.values(), color=colors).
Matplotlib
Need a hint?

Use plt.bar() with the keys and values of the dictionary and the colors list for the color argument.

4
Show the plot and print the sales data
Add plt.show() to display the chart. Then print the fruit_sales dictionary using print(fruit_sales).
Matplotlib
Need a hint?

Use plt.show() to display the chart. Then use print(fruit_sales) to show the dictionary.