Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook Homework Folder/AKoehler_12102015_Research_Proposal/Proposal_Graph.ipynb

69 views
Kernel: Python 2
%matplotlib inline import numpy as np import matplotlib.pyplot as plt points = np.array([(1, 1), (2, 4), (3, 1), (9, 3)]) # get x and y vectors x = points[:,0] y = points[:,1] # calculate polynomial z = np.polyfit(x, y, 3) f = np.poly1d(z) # calculate new x's and y's x_new = np.linspace(x[0], x[-1], 50) y_new = f(x_new) plt.plot(x,y,'o', x_new, y_new) plt.xlim([x[0]-1, x[-1] + 1 ]) plt.show()
Image in a Jupyter notebook
import matplotlib.pyplot as plt xp = np.linspace(-2, 6, 100) _ = plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--') plt.ylim(-2,2) plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-7-130f3eba9461> in <module>() 1 import matplotlib.pyplot as plt 2 xp = np.linspace(-2, 6, 100) ----> 3 _ = plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--') 4 plt.ylim(-2,2) 5 plt.show() NameError: name 'p' is not defined
from numpy import * import pylab # data to fit x = random.rand(6) y = random.rand(6) # fit the data with a 4th degree polynomial z4 = polyfit(x, y, 4) p4 = poly1d(z4) # construct the polynomial z5 = polyfit(x, y, 5) p5 = poly1d(z5) xx = linspace(0, 1, 100) pylab.plot(x, y, 'o', xx, p4(xx),'-g', xx, p5(xx),'-b') pylab.legend(['data to fit', '4th degree poly', '5th degree poly']) pylab.axis([0,1,0,1]) pylab.show() print p4
Image in a Jupyter notebook
4 3 2 -26.87 x + 44.51 x - 24.45 x + 5.447 x + 0.4641
from numpy import * import pylab # data to fit x = [0,20,40,60,80,120,160,180] y = [24.5,41.5,52.1,61.4,73.5,86,92.8,94] # fit the data with a 2nd degree polynomial z2 = polyfit(x, y, 2) p2 = poly1d(z2) # construct the polynomial xx = linspace(0, 200, 1000) pylab.plot(x, y, 'o', xx, p2(xx),'-g') pylab.axis([-20,200,0,100]) pylab.xlabel('Pounds of Nitrogen per Acre') pylab.ylabel('Crop Yield (Bushels)') pylab.title('Effect of Nitrogen Fertilizer on Corn Yield') pylab.show() print p2
Image in a Jupyter notebook
2 -0.002077 x + 0.7544 x + 25.4
import scipy as scipy t = linspace(0, 500, 1000) #import seaborn as sns #sns.residplot(x,y) scipy.stats(x,y)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-10-33314e658c6f> in <module>() 3 #import seaborn as sns 4 #sns.residplot(x,y) ----> 5 scipy.stats(x,y) AttributeError: 'module' object has no attribute 'stats'
from numpy import * import pylab # data to fit x = [0,20,40,60,80,120,160,180] y = [24.5,41.5,52.1,61.4,73.5,86,92.8,94] # fit the data with a 2nd degree polynomial z2 = polyfit(x, y, 2) p2 = poly1d(z2) # construct the polynomial xx = linspace(0, 500, 1000) pylab.plot(x, y, 'o', xx, p2(xx),'-g') pylab.axis([-20,500,0,100]) pylab.xlabel('Pounds of Nitrogen per Acre') pylab.ylabel('Crop Yield (Bushels)') pylab.title('Effect of Nitrogen Fertilizer on Corn Yield') pylab.show() print p2
Image in a Jupyter notebook
2 -0.002077 x + 0.7544 x + 25.4