0
0
Matplotlibdata~30 mins

Why statistical plots reveal data patterns in Matplotlib - See It in Action

Choose your learning style9 modes available
Why statistical plots reveal data patterns
📖 Scenario: You work as a data analyst for a small online store. You have sales data for different products over a week. You want to understand how sales vary and spot any patterns or trends.
🎯 Goal: Build a simple Python program that creates a dictionary of sales data, sets a threshold for high sales, filters the data, and then plots the sales using a bar chart to visually reveal patterns.
📋 What You'll Learn
Create a dictionary called sales with product names as keys and sales numbers as values
Create a variable called high_sales_threshold set to 50
Use a dictionary comprehension to create a new dictionary high_sales with only products having sales greater than high_sales_threshold
Use matplotlib.pyplot to plot a bar chart of high_sales
Print the high_sales dictionary
💡 Why This Matters
🌍 Real World
Data analysts often use plots to quickly understand sales trends, customer behavior, or product popularity.
💼 Career
Knowing how to filter data and visualize it is a key skill for data science, business analysis, and reporting roles.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales with these exact entries: 'Apples': 40, 'Bananas': 55, 'Cherries': 30, 'Dates': 70, 'Elderberries': 20
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Set the high sales threshold
Create a variable called high_sales_threshold and set it to 50
Matplotlib
Need a hint?

Assign the number 50 to the variable high_sales_threshold.

3
Filter high sales products
Use a dictionary comprehension to create a new dictionary called high_sales that includes only products from sales with sales greater than high_sales_threshold
Matplotlib
Need a hint?

Use {product: count for product, count in sales.items() if count > high_sales_threshold} to filter the dictionary.

4
Plot the high sales data and print the dictionary
Import matplotlib.pyplot as plt. Use plt.bar() to create a bar chart of high_sales keys and values. Then use plt.show() to display the plot. Finally, print the high_sales dictionary.
Matplotlib
Need a hint?

Use plt.bar() with high_sales.keys() and high_sales.values(). Then call plt.show(). Finally, print high_sales.