Fit a curve through points using python

RogerVL_1803

Hi everyone i'm trying to fit a curve through points using python, however I have not been succed, i'm a beginner using python and what i found it didn't help me.

I have a set of data and I want to analyse which line describes it best (polynomials of different orders).

In numpy and for polynomial fitting there is polyfit() and polyval(). But I am getting this error, and I do not know what it means:

File "plantilla.py", line 28, in <module>
polinomio=np.polyfit(x,y,5)
File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 581,   in polyfit
c, resids, rank, s = lstsq(lhs, rhs, rcond)
File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 1867,  in lstsq
0, work, lwork, iwork, 0)
ValueError: On entry to DLASCL parameter number 4 had an illegal value

import pandas as pd 
from matplotlib import pyplot as plt  
from scipy.optimize import curve_fit
import numpy as np
import sympy as sym

#----------------------------------------------------
data=pd.read_csv('radiacion.dat',header=None,delim_whitespace=True) 
x=data.ix[:,0] 
y=data.ix[:,1]
"""
x=np.array(x,dtype=float)
y=np.array(y,dtype=float)
"""
#----------------------------------------------------
plt.plot(x,y,'r',label="Original Data")
plt.title('Radiacion')
plt.xlabel('t(s)'  ,fontsize=14,fontweight='bold')
plt.ylabel('G(w/m)',fontsize=14,fontweight='bold')
plt.xticks(fontsize=10,fontweight='bold')
plt.yticks(fontsize=10,fontweight='bold')
plt.show ()
#plt.hold (True) 
#----------------------------------------------------
polinomio=np.polyfit(x,y,5)
print (polinomio)
yP=np.polyval(poli,x)
plt.plot(x,yp,'b+',label="fitted cuerve")

I expected something like this, to evaluate a polynomial at specific x values.

p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1]

My input data:

25200   17
25800   38
26400   58
27000   93
27600   129
28200   163
28800   192
29400   234
30000   329
30600   387
31200   411
31800   460
32400   513
33000   569
33600   576
34200   635
34800   645
35400   683
36000   715
36600   747
37200   780
37800   810
38400   833
39000   862
39600   885
40200   910
40800   929
41400   945
42000   955
42600   974
43200   986
43800   985
44400   999
45000   1001
45600   993
46200   993
46800   999
47400   992
48000   985
48600   980
49200   978
49800   963
50400   959
51000   939
51600   917
52200   884
52800   881
53400   860
54000   845
54600   820
55200   812
55800   767
56400   720
57000   650
57600   619
58200   595
58800   541
59400   533
60000   504
60600   456
61200   389
61800   320
62400   285
63000   243
63600   279
64200   231
64800   192
65400   137
66000   91
66600   58
67200   38
67800   22
68400   9
eusoubrasileiro

I have used your data exactly like you pasted on your question saving in a txt file. I don't get any errors! I think you have some problem with your original file.

here is the output.

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Curve fit an exponential decay function in Python using given data points

Python curve_fit with measured data points

How to fit curve through cloud of points? OpenCV/C++

R - fit a smooth curve through my data points

Curve fit in python using scipy.optimize.curve_fit

Monotonically decreasing curve fit using Python

Quantifying the quality of curve fit using Python SciPy

Is there a Python function for finding a function for the fit curve of a set of points?

Scipy - How to fit this beta distribution using Python Scipy Curve Fit

morse potential fit using python and curve fit from scipy

Python using curve_fit to fit a logarithmic function

Forcing data to fit points with curve_fit

Fit in python with curve_fit

How do i get a smooth fit for my data points, using "scipy.optimize.curve_fit"?

Fitting exponential function through two data points with scipy curve_fit

Fit a curve to a histogram in Python

Python Curve fit, gaussian

Multivariate curve fit in python

Curve Does not Fit (Python)

How to plot smooth curve through the true data points in Python 3?

Fitting a Lognormal Distribution in Python using CURVE_FIT

Fit sigmoid function ("S" shape curve) to data using Python

Using curve_fit to a function defined by indefinite integral in Python

Javascript array of points how to curve fit?

How to fit logarithmic curve over the points in r?

Wrong fit using scipy curve_fit

r fit logistic curve through a scatterplot

Curve fit passing through initial point and slope

Python - curve fit producing incorrect fit