Advertisement
khaiwen1111

1st file

Mar 8th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from scipy import optimize
  4. get_ipython().run_line_magic('matplotlib', 'inline')
  5. fig,ax = plt.subplots(figsize=(16,8))
  6. f=np.poly1d([5,1])
  7. x=np.linspace(0,20,30)
  8. y=f(x)+6*np.random.normal(size=len(x))
  9. m,c=np.polyfit(x,y,1)
  10. xn=np.linspace(0,20,200)
  11. yn=np.polyval([m,c],xn)
  12.  
  13. ##see the legend carefully, then open the another code and do side by side comparison##
  14.  
  15. ax.plot(x,y,"ob",label="data")
  16. ax.plot(xn,yn,label="polyfit",color="black")
  17. ax.plot(x,y,label="ntg")
  18. ax.plot(xn_1,yn,"red",label="polyfit12",)
  19. ax.legend(ncol=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement