0
0
Matplotlibdata~30 mins

Why interactivity enhances exploration in Matplotlib - See It in Action

Choose your learning style9 modes available
Why interactivity enhances exploration
📖 Scenario: Imagine you are a data scientist exploring sales data for a small store. You want to understand how sales vary by product category and month. Instead of looking at static charts, you want to interact with the data to see details on demand.
🎯 Goal: Build a simple interactive plot using matplotlib that lets you explore sales data by selecting different product categories. This will help you see why interactivity makes data exploration easier and more insightful.
📋 What You'll Learn
Create a dictionary called sales_data with monthly sales for three product categories.
Create a variable called selected_category to choose which category to explore.
Use a for loop to plot sales for the selected category over months.
Print the sales values for the selected category.
💡 Why This Matters
🌍 Real World
Data scientists often explore data interactively to find patterns and insights quickly. Interactivity lets them zoom in on details without creating many static charts.
💼 Career
Knowing how to create interactive visualizations is valuable for data analysts and scientists to communicate findings effectively and explore data efficiently.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Books': [120, 135, 150, 160], 'Electronics': [200, 210, 190, 220], and 'Clothing': [90, 100, 95, 105]. Each list represents sales for four months.
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary. Use the exact keys and lists as shown.

2
Select a product category to explore
Create a variable called selected_category and set it to the string 'Electronics' to choose which product category to explore.
Matplotlib
Need a hint?

Assign the string 'Electronics' to the variable selected_category.

3
Plot sales for the selected category
Use a for loop with variables month and sale to iterate over enumerate(sales_data[selected_category]). Inside the loop, use matplotlib.pyplot.bar to create a bar chart of sales by month. Use month as the x-axis and sale as the height.
Matplotlib
Need a hint?

Use enumerate to get month index and sale value. Use plt.bar inside the loop to plot each month.

4
Print the sales values for the selected category
Write a print statement to display the sales list for the selected_category from sales_data.
Matplotlib
Need a hint?

Use print(sales_data[selected_category]) to show the sales list.