Skip to content
Advertisement

How to fit a power law to the dataframe and plot it?

I have two columns(rcs,range) in a dataframe.

rcs range
-40 12.9
-35 14.9
-30 22.9
-25 35.44
-20 43.48
-15 62.4
-10 92.4
-5 132.99
0 182.6
5 252.99

I want to plot a curve with equation rcs = range^4

I tried the following 1.as a polynomial curve fitting

JavaScript

enter image description here in the above plot,the curve is not a smooth curve and is not starting from -40

2.power law curve fit

JavaScript

this one giving me a wrong plot.the red line is not passing through the blue points enter image description here

how to solve the above issue using curve_fit?and plot

Advertisement

Answer

You can use numpy.polyfit and numpy.poly1d:

JavaScript

output:

polynomial fit

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement