Learn Without Walls
← Back to Python Practice Labs
Lab 9 of 10

Data Visualization with Matplotlib

Turning numbers into pictures

← Lab 8: pandas Lab 9 of 10 Lab 10: Capstone →
Loading Python + matplotlib... (this may take 15 to 20 seconds)
This lab loads pandas, numpy, and matplotlib: allow extra time on first load. Charts will appear below each Run button.

Concept Recap

matplotlib is Python’s foundational plotting library.

Worked Example

A labeled bar chart: run this to see matplotlib in action:

import matplotlib.pyplot as plt import matplotlib matplotlib.use('Agg') categories = ['Python', 'SQL', 'Tableau', 'Excel', 'R'] popularity = [85, 78, 62, 71, 45] fig, ax = plt.subplots(figsize=(8, 5)) bars = ax.bar(categories, popularity, color=['#1565C0','#2E7D32','#6A1B9A','#E65100','#00695C']) ax.set_title('Data Analyst Skills by Job Posting Frequency', fontsize=14, fontweight='bold') ax.set_ylabel('% of Job Postings', fontsize=12) ax.set_ylim(0, 100) for bar, val in zip(bars, popularity): ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 1, f'{val}%', ha='center', fontweight='bold') plt.tight_layout() plt.show()
Output will appear here...
Guided

Exercise 1: Monthly Sales Line Chart

Complete the line chart by filling in the blanks. Add a marker symbol and titles.

Output will appear here...
Hint: Marker options: 's' (square), '^' (triangle), 'D' (diamond). Title and ylabel should be descriptive strings in quotes.
Independent

Exercise 2: Study Hours vs. Exam Scores

Create a scatter plot for 10 students. Make up realistic data for hours studied (2 to 10) and exam scores (40 to 100). Color the dots by pass/fail (score ≥ 60 = green pass, red fail). Add axis labels and a title.

Output will appear here...
Hint: ax.scatter(study_hours, exam_scores, c=colors, s=100, alpha=0.8). Add a horizontal line at y=60 with ax.axhline(60, color='gray', linestyle='--', alpha=0.5, label='Pass line').
Challenge

Exercise 3: 2×2 Dashboard

Create a 2×2 subplot grid with four different chart types:

  1. Top left: Bar chart, monthly sales by category (Electronics, Clothing, Food)
  2. Top right: Line chart, monthly revenue trend over 6 months
  3. Bottom left: Histogram, distribution of test scores (use: [72,85,91,68,77,83,90,64,88,75,79,82,95,71,86,69,93,78,84,73])
  4. Bottom right: Horizontal bar chart, top 5 products by sales
Output will appear here...
Hint: Line: ax2.plot(months, revenue, marker='o', color='#1565C0'). Histogram: ax3.hist(scores, bins=6, color='#6A1B9A', edgecolor='white'). Horizontal bar: ax4.barh(products, prod_sales).
Mini Project

Mini Project: Q1 Management Report

You are presenting Q1 results to management. Create a professional 2 row figure:

Use plt.subplots(2, 2) and merge the top row with fig.add_subplot(2, 1, 1) approach, or use gridspec. Consistent colors and proper labels required.

Output will appear here...
Hint: The starter code is nearly complete, run it and study how gridspec works. Then customize colors, add more data labels, or change the metrics shown in the summary box.

Lab 9 Complete!

You’ve built bar charts, line charts, scatter plots, histograms, multipanel dashboards, and a full management report. Visualization is the final step that makes your analysis communicable.

Continue to Lab 10: Capstone Project →

← Lab 8: pandas Lab 9 of 10 Lab 10: Capstone →