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?
font
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.linspace0,10,100
y numpy.expx
But if you dont 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.linspace0,10,100:
xpoints.appendx
ypoints.appendnumpy.expx
x numpy.arrayxpoints
y numpy.arrayypoints
In1:
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
yk frac12r1sumrmrykm
where r5. Plot the first 500 data points of the original data and running average on the same graph.
Finally, use the command plot.savefigsunspotplot.pdf,formatpdf before your plot.show to save a pdf of your plot.
In:
Excercise 4
Make a plot of the socalled deltoid curve, which is a paramteric curve defined by
x2costhetacos2theta, y2sinthetasin2theta
where 0leqthetalttheta. 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: