# 6.00 Problem Set 7 # # Demo code of using pylab plotting # import pylab # make the numbers to be plotted t = pylab.arange(0.0,2.0,0.01) # floating point numbers from 0.0 to 2.0, spaced 0.01 s1 = t*2 # multiply each element in t by 2 s2 = t*3 # multiply each element in t by 3 pylab.figure() # start a new figure pylab.plot(t,s1,'-.m') # plot t on the x-axis, s1 on the y-axis, with magenta dash-dot line pylab.xlabel('x axis') # label the x axis pylab.ylabel('y axis') # label the y axis pylab.title('s1 vs. t') # set figure title pylab.figure() # start a new figure pylab.subplot(2,1,1) # divide the figure into 2 rows, 1 column, draw to first subplot pylab.plot(t,s1,'-r',t,s2,'+g') # plot s1 vs. t in red line, s2 vs. t in green plus symbols pylab.legend(('y=2t','y=3t'),loc='upper left') # give legend to the two plots, # put it in the upper left corner pylab.xlabel('top x axis') # label the x axis pylab.ylabel('top y axis') # label the y axis pylab.subplot(2,1,2) # draw to the second subplot pylab.plot(t,s2,'--b') # plot s2 vs. t in blue dashed line pylab.xlabel('bottom x axis') # label the x axis pylab.ylabel('bottom y axis') # label the y axis # call this ONCE AT THE END to show ALL the figures pylab.show()