0
0
Matplotlibdata~30 mins

Marker size variation in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Marker size variation
📖 Scenario: You are analyzing sales data for a small store. You want to visualize the sales amounts for different products using a scatter plot. To make the plot more informative, you will vary the size of the markers based on the sales amount.
🎯 Goal: Create a scatter plot where the marker size changes according to the sales amount for each product.
📋 What You'll Learn
Create a dictionary called sales with product names as keys and sales amounts as values.
Create a list called sizes that contains marker sizes based on the sales amounts.
Use matplotlib.pyplot to create a scatter plot with product names on the x-axis and sales amounts on the y-axis.
Set the marker sizes in the scatter plot using the sizes list.
Display the plot.
💡 Why This Matters
🌍 Real World
Visualizing sales data with marker size variation helps quickly identify which products sell more, making it easier to focus on popular items.
💼 Career
Data analysts and scientists often use scatter plots with varying marker sizes to represent additional data dimensions visually.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales with these exact entries: 'Apples': 50, 'Bananas': 30, 'Cherries': 70, 'Dates': 40, and 'Elderberries': 60.
Matplotlib
Need a hint?

Use curly braces {} to create the dictionary with the exact keys and values.

2
Create the sizes list based on sales
Create a list called sizes that contains the sales amounts multiplied by 10 for each product in sales. Use a list comprehension iterating over sales.values().
Matplotlib
Need a hint?

Use a list comprehension like [amount * 10 for amount in sales.values()].

3
Create the scatter plot with varying marker sizes
Import matplotlib.pyplot as plt. Use plt.scatter() to create a scatter plot with product names on the x-axis and sales amounts on the y-axis. Set the marker sizes using the sizes list. Use sales.keys() for x values and sales.values() for y values.
Matplotlib
Need a hint?

Use plt.scatter(list(sales.keys()), list(sales.values()), s=sizes) to plot.

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

Call plt.show() to display the figure window.