import numpy as np import matplotlib.pyplot as plt # this program is much more 'procedural' than good python can be, but we will learn as we go along n = 100 # the number of points we want to plot # the following 'loop' is a VERY poor way of making an array or list, but it is easy to understand at this point in the class x = [] # create an empty list y = [] for z in np.linspace(0,7,n): # ‘for loops’ cycle over a list, in this case a list of numbers generated by the numpy ‘linspace’ method, don’t forget the ‘:’ y.append(np.sin(z)) x.append(z) #create lists of x and y. Lists must be 'appended' to to extend fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x,y,'r-*') # could stop here, but can pretty it up a little xspan = max(x) -min(x) yspan = max(y) -min(y) minx = min(x) - 0.05*xspan maxx = max(x) + 0.05*xspan miny = min(y) - 0.05*yspan maxy = max(y) + 0.05*yspan ax.axis([minx,maxx,miny,maxy]) ax.set_title("Simple Sine plot") ax.set_xlabel("Radians") plt.show()