A document from MCS 275 Spring 2021, instructor David Dumas. You can also get the notebook file.

Quiz 11

MCS 275 Spring 2021 - David Dumas

Instructions:

Deadline

This quiz must be submitted in Gradescope by 12:00pm CST on Tuesday, April 6, 2021.

Topic

This quiz covers matplotlib, as discussed in Lectures 28-29.

Resources you are allowed to consult

Quizzes are INDIVIDUAL, closed book (except where noted below), and only allow access to specified resources. For this quiz you can access:

Point distribution

There are two problems on this quiz, numbered 2 and 3. The point breakdown is:

Points Item
3 autograder
4 problem 2
4 problem 3
11 total

No problem 1 (as usual)

Problem 2: Unclear implications

Here is a table showing yearly values for two quantities from 1996 to 2008.

year math PhDs uranium
1996 1122 1060
1997 1123 1054
1998 1177 1052
1999 1083 933
2000 1050 877
2001 1010 890
2002 919 856
2003 993 730
2004 1076 923
2005 1205 1035
2006 1325 1240
2007 1393 1300
2008 1399 1310

In this table,

  • The column labeled "math PhDs" shows the total number of mathematics doctoral degrees awarded in the US
  • The column labeled "uranium" shows the total amount of uranium stored at US nuclear power plants (in units of millions of ounces)

Use matplotlib to plot the variation of both quantities on the same set of axes (with the x axis showing the year). Each quantity should be shown as a line with dots marking the individual data points. PhDs and stored uranium should be shown in different colors. Include a legend.

The code in the cell below can be used to save some typing---it has the two rightmost columns of the table above converted to list literals.

Upload two files for this problem:

  • quiz11prob2.py: The script you wrote to make the plot
  • quiz11prob2.png or quiz11prob2.jpg: An image file that shows the plot produced by your script, which can be saved by matplotlib or captured as a screenshot.

Note: The image and script you submit must match, i.e. the image must be one that was created with the exact script you submit.

Data source for this problem: US NSF and US DOE via tylervigen.com

In [ ]:
# annual data for 1996 to 2008
math_phds_awarded  = [1122, 1123, 1177, 1083, 1050, 1010, 919, 993, 1076, 1205, 1325, 1393, 1399]
stored_uranium_Moz = [1060, 1054, 1052, 933, 877, 890, 856, 730, 923, 1035, 1240, 1300, 1310]

Problem 3: Zebra

Use matplotlib to make a density plot of the region in the xy plane where $0 \leq x \leq 5$ and $0 \leq y \leq 5$, where each pixel is colored according to the value of the function $$ f(x,y) = \sin( \sin( \sin( \sin( \cdots \sin(xy - x^2) \cdots )))) $$ where there are a total of 100 nested copies of the $\sin$ function. Use a 50x50 grid of points to make the plot.

(Hint: in discussion last week you used matplotlib to make a density plot of escape rates for quadratic polynomials of a complex variable in order to visualize Julia sets. That code might be a good starting place for your work here, but this question doesn't use complex numbers at all.)

Upload two files for this problem:

  • quiz11prob3.py: The script you wrote to make the plot
  • quiz11prob3.png or quiz11prob3.jpg: An image file that shows the plot produced by your script, which can be saved by matplotlib or captured as a screenshot.

Note: The image and script you submit must match, i.e. the image must be one that was created with the exact script you submit.

Revision history

  • 2021-04-04 Initial publication