COM6018 Data Science with Python

Week 5: Using Matplotlib

Jon Barker

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

In this lab

  • Reading datasets from CSV files
  • Making complex figures with subplots
  • Exploring distributions with scatter plots
  • Generating pie charts and stackplots
  • Plotting geographic data
  • Plotting a contour map of a mathematical function
Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

The Task

  • You are provided with some complex datasets.

  • For each dataset you are shown a plot or plots that you need to reproduce.

  • You need to write Matplotlib code to produce something as similar as possible.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

The Data

We will be using data from three separate datasets

https://en.wikipedia.org/wiki/List_of_offshore_wind_farms_in_the_United_Kingdom

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Plot 1

Global renewable energy production over time.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Plot 1b

Renewable energy production broken down by region.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Plot 2

The share of renewable energy sources changing over time.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Plot 3

Using the Iris data. Distribution of petal and sepal, lengths and widths.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python
Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Plot 4

Using the wind farm data. Location and size of wind farms in the UK.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Plot 5

Visualising the function .

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Obtaining the Jupyter Notebook

If you have cloned and pulled the module's GitHub repository then you should see,

materials/labs/
├── 050_using_matplotlib.ipynb
|-- ... etc
├── data
│   ├── renewable_energy.csv
│   ├── iris.csv
│   ├── wind_farms_uk.csv
│   ├── ... etc

The lab is 050_using_matplotlib.ipynb, and it will need the data files data/renewable_energy.csv, data/iris.csv and data/wind_farms_uk.csv,

Or you can download the notebook and data via links on Blackboard.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.
COM6018 Data Science with Python

Getting Help

  • If you are stuck just raise a hand to ask for help.

  • Feel free to discuss the lab with your neighbours.

  • Re-read the Matplotlib tutorial notes

  • Use the Matplotlib https://matplotlib.org/ documentation for reference.

Copyright © 2023–2025 Jon Barker, University of Sheffield. All rights reserved.