Download (right-click, save target as ...) this page as a jupyterlab notebook from: Lab15-HW


Exercise Set 15: Matplotlib

LAST NAME, FIRST NAME

R00000000

ENGR 1330 ES-15 - Homework

In [23]:
# Preamble script block to identify host, user, and kernel
import sys
! hostname
! whoami
print(sys.executable)
print(sys.version)
print(sys.version_info)
! pwd
atomickitty.aws
compthink
/opt/conda/envs/python/bin/python
3.8.3 (default, Jul  2 2020, 16:21:59) 
[GCC 7.3.0]
sys.version_info(major=3, minor=8, micro=3, releaselevel='final', serial=0)
/home/compthink/CECE-1330-PsuedoCourse/1-Lessons/Lesson09/Lab9/src
In [24]:
# Import dependencies!

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt  

Line Plots


Exercise 1

The table below contains experimental observations.

Elapsed Time (s) Speed (m/s)
0 0
1.01 3
2.07 7
3.3 12
4.2 20
5.3 30
6.1 45.6

Plot the speed vs time (speed on y-axis, time on x-axis) using a line plot. From examination of the plot, estimate the speed at time t = 5.0 (eyeball estimate)

In [25]:
# Create two lists; time  and speed
In [26]:
# Create a line chart of speed on y axis and time on x axis

# Estimate:

Exercise 2

Using the same series from Exercise 1, Plot the speed vs time (speed on y-axis, time on x-axis) using a scatter plot. From examination of the plot, estimate the speed at time t = 2.0 (eyeball estimate)

In [27]:
# Create a scatterplot chart

# Estimate: 

Exercise 3

Using the same series from Exercise 1, Plot the speed vs time (speed on y-axis, time on x-axis) using a line plot. Plot a second line based on the linear model

$$y = mx + b$$

where

$$b=0~\text{and}~m=7.6$$
In [28]:
# Code and run your solution here:

Exercise 4

Using trial and error try to improve the 'fit' of the model, by adjusting values of $$m~\text{and}~b$$.

In [29]:
# Code and run your solution here:

Exercise 5

Use pandas to read a dataframe from the file http://54.243.252.9/engr-1330-webroot/8-Labs/Lab15/census_18.csv. Then produce a line plot of the counts by age for the 2010 census, x-axis will be the series age, y-axis will be the census values for 2010.

In [1]:
######### CODE TO AUTOMATICALLY DOWNLOAD THE DATABASE ################
import requests # import needed modules to interact with the internet
# make the connection to the remote file (actually its implementing "bash curl -O http://fqdn/path ...")
remote_url = 'http://54.243.252.9/engr-1330-webroot/8-Labs/Lab15/census_18.csv' # a csv file
response = requests.get(remote_url) # Gets the file contents puts into an object
output = open('census_18.csv', 'wb') # Prepare a destination, local
output.write(response.content) # write contents of object to named local file
output.close() # close the connection
In [30]:
# Code and run your file read here
In [31]:
# Code and run your plot here

Exercise 6

Using your dataframe from exercise 5, plot both the 2010 and 2014 census values by age. Plot the 2010 distribution in blue and the 2014 distribution in red.

In [32]:
# Code and run your plot here

Bar Charts


Exercise 7

Consider the data set "data" defined as

data = {'C':20, 'C++':15, 'Java':30, 'Python':35} 

which lists student count by programming language in some school.

Produce a bar chart of number of students in each language, where language is the classification, and student count is the variable.

In [34]:
# Code and run your solution here

Exercise 8

Repeat Exercise 7 but use a horizontal bar chart.

In [35]:
# Code and run your solution here