Home Practicum 1 Practicum 2 Practicum 3 Practicum 4 Practicum 5 Practicum 6 Practicum 7 Practicum 8 Practicum 9 Practicum 10 Practicum 11

Welcome to DS2000 CS Practicum 11!

Introduction

Today we will practice presenting time data and histograms with matplotlib.

Installing matplotlib on a Windows machine

Open command line (CMD.exe) and type the following commands one by one:
  1. c:
  2. cd "C:\Program Files\Python37\" (If you get the error already here, ask me for help)
  3. python.exe -m pip install -U pip --user
  4. python.exe -m pip install -U matplotlib --user
  5. Close all windows of IDLE and open them again. In the console window type import matplotlib to make sure it worked.

Installing matplotlib on a MacOS machine

Open your Terminal (Cmd + Space, type terminal) and type in the following commands:
  1. cd "/Applications/Python 3.7/IDLE.app/Contents/MacOS/"
  2. ./Python -m pip install -U pip (there is a dot in the beginning of this command!)
  3. ./Python -m pip install -U matplotlib (there is a dot in the beginning of this command as well!)
  4. Close all windows of IDLE and open them again. In the console window type import matplotlib to make sure it worked.

Exercise 1: line plot

  1. Download this CSV file. It has a list of temperatures day by day in Boston in February 2019. Columns contain the following information: day, max temperature, average temperature, minimum temperature.
  2. Download this starter code that reads the temperature data and shows the average temperature per day.
  3. Now you know how to make a line plot and set the color. To add more lines in the same plot, use plt.plot again before calling plt.show().
  4. In the same plot add the minimum temperatures with blue and maxiumim temperatures with red.
  5. All plots always need to have their axes labeled. You see in the code how I labeled the x-axis, set a label on the y-axis as well.
  6. We have three lines with different colors, but what does each mean? Uncomment the #plt.legend() line to show the legend. If your blue and red lines do now show in the legend, make sure you set their labels!
  7. Save the figure using the save button and attach it to your submission.

Exercise 2: histograms

  1. Use the plt.hist() function to show a distribution of daily average temperatures. Make sure to label the axes correctly!
  2. plt.hist() has a parameter bins. See what happens if you set it to 5 and then to 28.
  3. Save the figure using the save button and attach it to your submission.

Exercise 3: scatter plots

We can visualize that two variables are correlated (or not) using a scatter plot. Let's see if the temperature on one day is correlated with the temperature on the next day.

  1. Read the tutorial on list splicing here https://www.pythoncentral.io/how-to-slice-listsarrays-and-tuples-in-python/. Just the "Slicing Python Lists/Arrays and Tuples Syntax" part, without the Advanced...
  2. Use plt.scatter() to plot the relations between the temperature on days 0:27 and the temperatures on days 1:28.
  3. Save the figure using the save button and attach it to your submission.