DS105 2025-2026 Winter Term Icon

๐Ÿ’ป Week 05 Lab

Matplotlib, Seaborn & Your First Visualisations

Author

Dr Jon Cardoso-Silva

Published

18 February 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