程序代写代做代考 Homework 04 – Matplotlib tutorial¶

Homework 04 – Matplotlib tutorial¶

Excercise 1¶
Plot exactly two cycles of a sine curve, in any style you choose. Annotate one peak and one trough of the curve.

Is the curve smooth to your eye?

Some advice¶
One quick way to generate data if you know ahead of time the number of data points you want to create is like this:
x = numpy.linspace(0,10,100)
y = numpy.exp(-x)
But if you don’t know how many values you will be generating, or all the values ahead of time, then you can do it by appending data to a list as you go along:
xpoints = []
ypoints = []
for x in numpy.linspace(0,10,100):
xpoints.append(x)
ypoints.append(numpy.exp(-x))
x = numpy.array(xpoints)
y = numpy.array(ypoints)

In [1]:
%matplotlib inline
import numpy # numpy functions must be used like `numpy.function`
import matplotlib.pyplot as plot # matplotlib funcitons must be used like `plot.function`
In [ ]:

Excercise 2¶
A. Check the file type of the data files associated with this notebook: `dow.txt` and `sunspots.txt`
B. Plot the `sunspot.txt` file again, but this time use the `unpack` option of `numpy.loadtxt` to avoid the need to slice the data. Do not use variables `x` or `y`, but directly use the data returned from `numpy.loadtxt` into `plot.plot` Modify the plot to only plot the first 750 data points.
In [ ]:

Excercise 3¶
Plot the `sunspot.txt` file once again, but this time plot a running average of the data, defined by
$$y_k = \frac{1}{2r+1}\sum^{r}_{m=-r}y_{k+m}$$
where $r=5$. Plot the first 500 data points of the original data and running average on the same graph.
Finally, use the command plot.savefig(“sunspot_plot.pdf”,format=”pdf”) before your `plot.show()` to save a pdf of your plot.
In [ ]:

Excercise 4¶
Make a plot of the so-called deltoid curve, which is a paramteric curve defined by
$$x=2\cos\theta+\cos2\theta,\ \ y=2\sin\theta-\sin2\theta$$
where $0\leq\theta\lt\theta$. Take a set of values of $\theta$ between these limits and calculate $x$ and $y$ for each of them, then plot $y$ as a function of $x$.

In [ ]: