Assignment 5 - Visualizing Data

Due: Thursday, October 16, 2025, at 10pm

You may work alone or with a partner, but you must type up the code yourself. You may also discuss the assignment at a high level with other students. You should list any student with whom you discussed each part, and the manner of discussion (high-level, partner, etc.) in a comment at the top of each file. You should only have one partner for an entire assignment.

You should submit your assignment on Gradescope. See below for which files to submit.


Getting started:

You will do all of your work in a single file, weatherPlotter.py. You should download this “skeleton” version, and save it as weatherPlotter.py.

Additionally, you will need the same data file that you used for weather data in Assignment 4. Make sure to save it in the same folder as weatherPlotter.py.


Goals

The primary goal for this assignment is to give you practice visualizing datasets programmatically using matplotlib.


Parts of this assignment:


Comments and collaboration

# You should be equipped to complete this part right away.

As with all assignments in this course, for each file in this assignment, you are expected to provide top-level comments (lines that start with # at the top of the file) with your name and a collaboration statement. For this assignment, you have multiple programs; each needs a similar prelude.

You need a collaboration statement, even if just to say that you worked alone.


Note on style:

The following style guidelines are expected moving forward, and will typically constitute 5–10 points of each assignment (out of 100 points).

  • Variable names should be clear and easy to understand, should not start with a capital letter, and should only be a single letter when appropriate (usually for f as a file, i, j, and k as indices, potentially for x and y as coordinates, and maybe p as a point, c for a circle, r for a rectangle, etc.).
  • It’s good to use empty lines to break code into logical chunks.
  • Comments should be used for anything complex, and typically for chunks of 3–5 lines of code, but not every line.
  • Don’t leave extra print statements in the code, even if you left them commented out.
  • Make sure not to have code that computes the right answer by doing extra work (e.g., leaving a computation in a for loop when it could have occurred after the for loop, only once).
  • Avoid having tons of lines of code immediately after another that could have been in a loop.

Note: The example triangle-drawing program on pages 108–109 of the textbook demonstrates a great use of empty lines and comments, and has very clear variable names. It is a good model to follow for style.


Part 0: Parsing the dtaa

You already did this! Copy your parseData function from weatherParser.py into the starter code for this assignment, weatherPlotter.py.


Part 1: Making a line graph

# You should be fully equipped to complete most of this part after Lesson 12 (Friday Oct. 10).

Part a: Install matplotlib

This assignment will require Matplotlib, so make sure to get it if you haven’t already. You can get it from the command prompt (search “cmd” in Windows or “Terminal” on a Mac), with the following command:

pip3 install matplotlib

Note that if you are on a Mac and get a message about brew/homebrew and that you should install it using a virtual environment, make sure to refer back to our Getting Started instructions and do steps 2b, 2e, and 2d to make sure you can install it.

Once you’ve got it, you should be able to run the starter code in weatherPlotter.py and make sure the from matplotlib import pyplot as plt line doesn’t have an error. You can also test out your code with the example program from Lesson 12.

Part b: a line graph

Given the data you’ve parsed out of the file, you should plot the data using Matplotlib. Your plot should have:

  • both the minimum and maximum values in the same plot
  • a title
  • axes labels
  • a legend

Hint: Check out the function plot. Note that formal parameters listed with [] are optional (like the x-axis values, x, and the line format, fmt).

Here is what it should look like:

<image: plot of temperatures in 2023>

To do this, fill in the function plotTempData:

def plotTempData(minTemps, maxTemps):
    """
    Plots both the minimum and maximum temperature for each day
    in the same plot.
    """
    # TODO: Part 1
    pass # replace with your code

For this assignment (and no others), you are encouraged to explore online for help using Matplotlib. This can include the Matplotlib documentation and stack overflow, but should not include tools to generate code for you, like ChatGPT or Copilot. Just make sure to cite any website (with the full URL) you visit in your reflection at the bottom of weatherPlotter.py. Note that you should still only be collaborating closely (e.g., viewing code) with your partner, if you choose to have one.


Part 1: Making another plot

Come up with another interesting plot that uses:

  • at least one of precipitation or snow data
  • the dates

For full credit, you must do something interesting with the data, not just make a line plot for the entire year like in Part 1.

For example, you could calculate the total snowfall for each month and make a bar graph with one bar per month. Or, you could make separate preciptation lists for each month, and make a line graph with all twelve months on the same plot as different lines.

Put your new plotting code in another function, and make sure to modify main to call it. Your function should have a docstring, and your plot should have a title and a legend.

def main():
    # Parse the temperature data into lists of dates, precipitation,
    # snow, lows, and highs
    filename = "weatherData.csv"
    dates, precip, snow, mins, maxes = parseData(filename)

    # Plot the low/high temperatures on the same axes
    plotTempData(mins, maxes)

    # TODO: Part 2
    pass # replace with a call to another plotting function

The same rules apply for Part 2 as they do for Part 1: you are encouraged to explore online for help using Matplotlib. This can include the Matplotlib documentation and stack overflow, but should not include tools to generate code for you, like ChatGPT or Copilot. Just make sure to cite any website (with the full URL) you visit in your reflection at the bottom of weatherPlotter.py.


Reflection

# You should be equipped to complete this part after finishing your assignment.

Were there any particular issues or challenges you dealt with in completing this assignment? How long did you spend on this assignment? Write a brief discussion (a sentence or two is fine) in comments at the bottom of weatherPlotter.py.


Grading

This assignment will be graded out of 100 points, as follows:

  • 5 points - submit a valid weatherPlotter.py file with the right name
  • 5 points - weatherPlotter.py file contains top-level comments with file name, purpose, author names, and collaboration statement

  • 10 points - code style enables readable programs

  • 35 points - plotTempData function correctly plots the data returned from parseData (20 pts), and includes a title, legend, and x- and y-axis labels (15 pts) (Part 1)

  • 35 points - a new graph is created by a function (5 pts), uses dates and at least one of precip/snow data (15 pts) in an interesting way (10 pts), and the plot has a title and legend (5 pts) (Part 2)

  • 10 points - weatherPlotter.py file contains reflection and citations


What you should submit

You should submit the following files on Gradescope:

  • weatherPlotter.py (Parts 1+2 and reflection)