DS105 2025-2026 Winter Term Icon

πŸ’» Week 05 Lab

Matplotlib, Seaborn & Your First Visualisations

Author

Dr Jon Cardoso-Silva

Published

18 April 2026

πŸ₯… Learning Goals

By the end of this lab, you should be able to: i) Set up matplotlib and seaborn with proper imports and configuration, ii) Understand the role of figure and axes objects in matplotlib, iii) Create bar plots, line charts, and scatter plots with seaborn, iv) Apply the plot_df pattern and write narrative titles, v) Export plots as PNG and SVG files.

This lab builds on πŸ–₯️ W05 Lecture where you learned custom functions, .apply(), .groupby(), and pandas Styler. Today you’ll learn the other presentation path for your Mini-Project 1: creating plots with matplotlib and seaborn.

πŸ“‹ Preparation

  • Attend or at least watch the πŸ–₯️ W05 Lecture
  • Find a partner for pair programming. You’ll swap roles for Task 03 (your class teacher will mediate this)

πŸ›£οΈ Lab Roadmap

Task Activity Type Focus Time Outcome
Task 01 πŸ—£οΈ TEACHING MOMENT Matplotlib Scaffolding 20 min Imports, config, figure/axes understanding
Task 02 πŸ—£οΈ TEACHING MOMENT Seaborn Bar Plot 10 min Follow-along: the plot_df pattern
Task 03 🎯 ACTION POINTS Pilot/Copilot Plots 40 min Line chart + scatter plot + narrative titles
Task 04 🎯 ACTION POINTS Challenge Plot 20 min London vs Paris comparison + explanation
Wrap-Up πŸ—£οΈ TEACHING MOMENT MP1 Connection 10 min Connect lab skills to NB03

πŸ’‘ Today’s Design: Tasks 01-02 build mechanical comfort with the plotting infrastructure. Tasks 03-04 are pair programming exercises where you apply everything together.

Task 01: Matplotlib Scaffolding (20 min)

Note to class teachers: Students work through this individually. The goal is mechanical comfort with the plotting infrastructure so Task 02 and 03 feel smooth. Circulate to check imports are working.

Setup for Today:

  1. Check that you can see the notebook and data file

    These should be in your Nuvolos folder already. If not, use the buttons below to download the materials and save them to /files/week05/ on Nuvolos.

🌟 Optional: If you have been following my suggestions from the W03 Lecture

If you have been following my suggestions from the W03 Lecture, you should already have a my-ds105-notes repository!

You can copy these files there for backup:

# Copy notebook and data to your Git repository
cp /files/week05/W05-NB02-Lab.ipynb /files/my-ds105-notes/week05/
cp /files/week05/data/london_paris_weather.csv /files/my-ds105-notes/week05/data/

Then work from /files/my-ds105-notes/week05/ instead. This way your work is version-controlled!

  1. Open the notebook and work through the Task 01 cells

You’ll learn:

  • Installation check: Verify matplotlib and seaborn are available
  • The import block: import matplotlib.pyplot as plt and import seaborn as sns
  • SVG configuration: Crisp rendering with %config InlineBackend.figure_formats = ['svg']
  • plt.figure(): Creating a canvas with configurable size
  • plt.tight_layout(): Preventing label clipping
  • plt.savefig(): Exporting plots as PNG and SVG files

🎯 ACTION POINTS

  1. Run the installation check cell
  2. Run the import and config cells
  3. Try changing figsize to (4, 4) and (12, 3) to see how it affects the canvas
  4. Save a test plot as both PNG and SVG. Open them in your file browser and compare zoom quality

Task 02: Seaborn Bar Plot (10 min)

Note to class teachers: This is a follow-along teaching moment. Walk through the plot_df pattern step by step. Emphasise: prepare data first, inspect it, then plot. If students rush to sns.barplot() without preparing plot_df first, slow them down.

Follow along as we build a bar plot using the london_paris_weather.csv dataset. Every seaborn plot follows the same workflow:

  1. Prepare a plot_df with exactly the columns you need
  2. Inspect it with print(plot_df)
  3. Plot with seaborn
  4. Title with a narrative that states your finding
  5. Save to figures/

The notebook walks through each step for a bar plot of London’s monthly rainfall. After completing it, review the Seaborn Quick Reference table before moving on.

Task 03: Pilot/Copilot Plots (40 min)

Note to class teachers: Students swap roles and work through two plots independently. The notebook provides hints but not complete code. Circulate and check that pairs are discussing before coding, and that narrative titles state findings rather than describe the chart.

⚠️ SWAP ROLES! The person who was NOT typing becomes the πŸ§‘β€βœˆοΈ Pilot.

Apply the same workflow you just saw. The notebook provides hints for each plot.

🎯 ACTION POINTS

  1. πŸ§‘β€βœˆοΈ Pilot Plot A: Line chart of London’s yearly temperature trend. Write a narrative title and save to figures/.

  2. πŸ§‘β€βœˆοΈ Pilot Plot B: Scatter plot of temperature vs rainfall. What pattern do you see? Write a narrative title and save to figures/.

  3. πŸ‘₯ Together Discuss: For each plot, does your title state a finding or just describe the chart?

Task 04: Challenge Plot (20 min)

Note to class teachers: Students stay in their pairs. The key teaching moment is the choice of plot type and what to aggregate. Push students to discuss before coding.

Still in your pairs, create ONE visualisation that answers:

β€œHow do London and Paris compare in their seasonal temperature patterns?”

🎯 ACTION POINTS

  1. πŸ™‹ Copilot Guide what to aggregate and which plot type to use (discuss before coding!)

  2. πŸ§‘β€βœˆοΈ Pilot Prepare plot_df, create the plot with a narrative title, export as PNG and SVG to figures/

  3. πŸ‘₯ Together Write 2-3 sentences explaining what plot type you chose, why, and what your title communicates

Optional stretch goal: If you finish early, try using seaborn’s FacetGrid to create side-by-side plots. Attempt it based on the docs alone before consulting other sources.


Wrap-Up & Next Steps (10 min)

Note to class teachers: Connect today’s skills to MP1. Remind students of the Reading Week timeline. Emphasise that students now have TWO paths for their NB03 insights.

Class Discussion:

You now have two paths for Mini-Project 1 NB03 insights:

  • Styled DataFrames (learned in yesterday’s lecture): .style.format(), .background_gradient(), .set_caption()
  • Seaborn plots (learned today): sns.barplot(), sns.lineplot(), sns.scatterplot()
  • You can mix: one styled DataFrame + one seaborn plot

Looking Ahead:

  • ✍️ Mini-Project 1 deadline: Thursday 26 Feb at 8pm
    • Your loop-based NB02 code should now be translated to vectorised operations (using .apply() and .groupby() from yesterday’s lecture)
    • Reading Week drop-in sessions available (check βœ‹ Contact Hours)
  • Week 06: Reading Week, dedicated time to complete Mini-Project 1

πŸ”— Useful Resources

πŸ“Š Essential Guides

πŸ’» Course Materials

  • πŸ–₯️ W05 Lecture: Custom functions, groupby, pandas Styler
  • πŸ–₯️ W04 Lecture: Vectorisation with NumPy and Pandas
  • ✍️ Mini-Project 1: Your first assessed project (due Week 06)

πŸ†˜ Getting Help

  • Slack: Post questions to #help channel
  • Office Hours: Book via StudentHub
  • Check staff availability on βœ‹ Contact Hours

🌐 External Resources