Skip to content

Instantly share code, notes, and snippets.

@urigoren
Created October 10, 2017 12:33
Show Gist options
  • Save urigoren/7188607d761ce2386e5507842dd7c891 to your computer and use it in GitHub Desktop.
Save urigoren/7188607d761ce2386e5507842dd7c891 to your computer and use it in GitHub Desktop.
import numpy as np
from matplotlib import pyplot as plt
def polyfit_plot(x, y, p=1):
plt.scatter(x, y)
axes = plt.gca()
coeff = np.polyfit(x, y, p)
X_plot = np.linspace(axes.get_xlim()[0],axes.get_xlim()[1],100)
print (np.corrcoef(x,y)[0,1])
Y_plot = 0
for c in coeff:
Y_plot = X_plot*Y_plot + c
plt.plot(X_plot, Y_plot, '-')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment