Skip to content

Instantly share code, notes, and snippets.

@dragstar328
Last active May 24, 2016
Embed
What would you like to do?
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
from scipy import optimize as opt
kion = pd.read_csv("kion_20160501.csv")
kion.head()
Px = np.arange(0, len(kion), 1)
Py = kion['temp']
plt.plot(Px, Py)
plt.show()
def fit_func(x, a, b, c, d):
return a * x**3 + b * x**2 + c * x + d
res = opt.curve_fit(fit_func, Px, Py)
a = res[0][0]
b = res[0][1]
c = res[0][2]
d = res[0][3]
print("a = %s" % (a))
print("b = %s" % (b))
print("c = %s" % (c))
print("d = %s" % (d))
Px2 = []
for x in Px:
Px2.append(a * x**3 + b * x**2 + c * x + d)
plt.plot(Px, Py)
plt.plot(Px, np.array(Px2))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment