Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- from scipy import optimize
- get_ipython().run_line_magic('matplotlib', 'inline')
- fig,ax = plt.subplots(figsize=(16,8))
- f=np.poly1d([5,1])
- x=np.linspace(0,20,30)
- y=f(x)+6*np.random.normal(size=len(x))
- m,c=np.polyfit(x,y,1)
- xn=np.linspace(0,20,200)
- yn=np.polyval([m,c],xn)
- xn_1=np.linspace(0,15,200)
- ##see how i manipulate the position of data displayed according to the legend ur lect provided##
- ##it should be followed by the variable of ur plot, then the title of ur legend##
- ## also note that there is no label in the ax.plot, it wont conflict but to avoid confusion#
- ## note that there is a comma at the variable##
- ##it is because without that comma,the plt returns those variable as a tuple, instead of a line object##
- data,=ax.plot(x,y,"ob")
- polyfit,=ax.plot(xn,yn,color="black")
- ntg,=ax.plot(x,y)
- polyfit12,=ax.plot(xn_1,yn,"red")
- ax.legend((polyfit12,polyfit,ntg,data),(["Linear fit first 12 points","Linear fit first 20 points","polynomial fit","datapoints"]),ncol=2)
Add Comment
Please, Sign In to add comment