0
0
Matplotlibdata~30 mins

Bubble charts concept in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Bubble Chart with Matplotlib
📖 Scenario: You work as a data analyst for a small company. Your manager wants to see a visual comparison of sales data for different products. You will create a bubble chart to show the sales volume, profit, and number of customers for each product.
🎯 Goal: Build a bubble chart using matplotlib that shows product sales data. The x-axis will represent sales volume, the y-axis will represent profit, and the size of each bubble will represent the number of customers.
📋 What You'll Learn
Create a dictionary called sales_data with product names as keys and tuples of (sales volume, profit, customers) as values.
Create a variable called scale_factor to adjust bubble sizes.
Use a for loop with variables product and values to iterate over sales_data.items().
Plot bubbles using plt.scatter with correct x, y, and size values.
Add labels for x-axis, y-axis, and a title.
Print the plot using plt.show().
💡 Why This Matters
🌍 Real World
Bubble charts help businesses visualize relationships between three variables at once, such as sales, profit, and customer count.
💼 Career
Data analysts and scientists use bubble charts to present complex data clearly to managers and stakeholders.
Progress0 / 4 steps
1
Set up the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Product A': (100, 30, 40), 'Product B': (150, 45, 60), 'Product C': (80, 20, 30), 'Product D': (200, 70, 90).
Matplotlib
Need a hint?

Use curly braces {} to create the dictionary. Each key is a product name string, and each value is a tuple with three numbers.

2
Create a scale factor for bubble sizes
Create a variable called scale_factor and set it to 10. This will help adjust the size of the bubbles in the chart.
Matplotlib
Need a hint?

Just write scale_factor = 10 on a new line.

3
Plot the bubble chart using a for loop
Import matplotlib.pyplot as plt. Use a for loop with variables product and values to iterate over sales_data.items(). Inside the loop, use plt.scatter to plot bubbles where x is sales volume, y is profit, and size is customers multiplied by scale_factor. Add labels for x-axis as 'Sales Volume', y-axis as 'Profit', and a title 'Sales Bubble Chart'.
Matplotlib
Need a hint?

Remember to unpack values into sales_volume, profit, and customers. Use plt.scatter(x, y, s=size) to plot bubbles. Use alpha=0.5 for transparency and label=product to label each bubble.

4
Display the bubble chart
Add a legend to the plot using plt.legend(). Then print the plot using plt.show().
Matplotlib
Need a hint?

Use plt.legend() to show the labels for each bubble. Then call plt.show() to display the chart.