Review Questions
Review Questions
5.01 Create a line plot with y-values equal to y = [1, 4, 12, 23]
and x-values set to the default values by Matplotlib
5.02 Create a line plot with x-values equal to x = [0, 3, 6, 9, 12, 15]
and y-values equal to y = [-6, -1, 0, 4, 10, 8]
5.03 Create a plot of the function y=\cos(x) from x = -2\pi to 2\pi
5.04 Plot the two functions y_1 and y_2 below on the same set of axis. Use a different color line for each function.
Set values of x =-4\pi to 4\pi in increments of 0.1 radians.
5.05 A list of grades in a college programming course and the corresponding number of students who earned each grade is shown below:
grades = ['A','B','C','D','F']
number_of_students =[8, 12, 19, 1, 2]
Build a bar plot of the grade distribution from the college engineering class. Include grades
on the x-axis and number_of_students
on the y-axis.
5.06 The tensile strength of four steel heat treatments and the corresponding tensile strength is below.
Heat Treatment | Tensile Strength (MPa) |
---|---|
Annealed | 390 MPa |
Normalized | 452 MPa |
Oil Quench | 734 MPa |
Oil Quench and Temper | 422 MPa |
Build a bar plot of tensile strength vs. heat treatment using the data above.
5.07 According to the University of Waterloo, world energy consumption in 2006 from the 5 top energy resources were:
Build a pie chart of distribution of world energy consumption based on the data above. Include the energy type (Hydro, Nuclear, Oil, etc) as labels. Include the percentage contributed by each energy title on the pie chart.
5.08 Use the code below to build an array x
of 100 random numbers with a normal distribution with a mean of 15 and a standard deviation of 2.
mu = 15
sigma = 2
x = np.random.normal(mu, sigma, size=100)
Build a histogram of the array x
using Matplotlib's plt.hist()
function. Include the title 'Histogram'
and make the bars in the histogram green and half-transparent (alpha = 0.5
).
5.09 Create a scatter plot with the following lists of x points and y points.
x = [0, 5, 10, 15, 20]
y = [-80, -24, 0, 40, 65]
Label the x-axis 'x-axis'
and label the y-axis 'y-axis'
. Include the title 'Scatter Plot'
.
5.10 Use the code below to create two arrays of semi-focused random points.
x1 = 1.5 * np.random.randn(150) + 8
y1 = 1.5 * np.random.randn(150) + 8
x2 = 1.5 * np.random.randn(150) + 2
y2 = 1.5 * np.random.randn(150) + 2
x = np.append(x1,x2)
y = np.append(y1,y2)
Plot the arrays x
and y
on a scatter plot. Make the marker color on the scatter plot red (color = 'r'
). Set the marker size to 20 pt (size=20
), and set the marker opacity to 50% (alpha=0.5
).