#! /usr/bin/python

import scipy as sc
import numpy as np
import math
import matplotlib.pyplot as plt

def parabolaFit(x,a):
#   print x,a
   return -a[0]*(x-a[1])**2+a[2]

degree = 3
data = np.loadtxt('tracking_pab/2D_line_velocity_in_p00000_t00000112.800E+03.res')
x = data[:,1]
y = data[:,3]
a = [0.05, 0.41/2.0, 0.05]
b = np.polyfit(x,y,2)
f = np.poly1d(b)
res = f(x)#np.insert(f(x),f(4.1),f(0))
res2 = np.insert(res,[0,len(res)],[f(0),f(0.41)])
x2 = np.insert(x,[0,len(x)],[0.0,0.41])

plt.plot(x,y,'o', label='original')
plt.plot(x2,res2,'r',label='fit')
plt.show()
