# load arrays with coordinates of points on a unit circle, then plot them # this file is unit02_draw_circles.py # import the numpy and matplotlib.pyplot libraries import numpy as np import matplotlib.pyplot as plt # create the arrays. first is angle, running from [0,2pi). Note the use of # endpoint = False in linspace to make this interval open on the right. The # first two arguments in linspace are the beginning and end of the interval # of uniformly spaced points. The third is the total number of points. ThetaArray = np.linspace(0, 2*np.pi, 36, endpoint=False) # cos and sin in numpy can act on all elements in an array. Note that the # output is also an array. x = np.cos(ThetaArray) y = np.sin(ThetaArray) # set the size for figures so that they are square. (Units: inches???) plt.figure(figsize=(8.0, 8.0)) # also set the x and y axis limits plt.xlim(-1.2, 1.2) plt.ylim(-1.2, 1.2) # plot the x,y points, connecting successive points with lines plt.plot(x,y) # now plot the points again, on the same axes, but using red + signs: plt.plot(x,y, 'r+') # now redo the array of angles (and x,y points) to include the 2pi endpoint. # make a smaller circle this time... ThetaArray = np.linspace(0, 2*np.pi, 36, endpoint=True) x = 0.8*np.cos(ThetaArray) y = 0.8*np.sin(ThetaArray) #plot it. note how the line color changes... plt.plot(x,y) # now make an oval by down-scaling the x, y arrays, then plot # it using rather large, filled blue circles. x = 0.7 * x y = 0.4 * y plt.plot(x,y, 'bo', markersize=12) # now put a title onto the plot, then label the axes plt.title("Some circles and ovals-- George Gollin") plt.xlabel("X") plt.ylabel("Y") # now save plot to a png (portable network graphics) file plt.savefig("CirclePlotOne.png")