I'm working on an investigation proyect, where I have to plot some experimetal data, and then find the max value (critical point), like on this image:
I was trying to adjust a fit curve (using a cuadratic equation) in order to find that max value, and I am looking to optimize that curve right now. I've tried with maxarray, but there is an specific value that doesn´t fix to the tendence.
This is what I've done until now:
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np
import scipy
# Subo los datos experimentales #
datos=np.loadtxt("OFET2.txt", delimiter="\t")
x=datos[:,1]
y=datos[:,4]
n=len(x)
dr=np.diff(y)/np.diff(x)
dx=datos[:n-1,1]
def func(x, a, b, c):
return -(a*x+b*x**2-c) # Este x no tiene nada que ver con el dato de x
plt.plot(dx, dr, label='experimental-data')
popt, pcov = curve_fit(func, dx, dr)
print(popt)
#x values for the fitted function
xFit = np.arange(-100, 400, 0.01)
#Plot the fitted function
plt.plot(xFit, func(xFit, *popt), 'r--', label='fit params: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.legend()
plt.show()
And here there is an image of that plot:
An idea was to fit the curve just to the "y" values greater than 0.008 (y<0.008), but actually I don't know how to do it. After that, I would need to (somehow) point the max value of the curve. I should try to get something like this I would be really thankful if you could help me to solve this,either like on the first image, or fixing my script. I am also keen on any advice or correction you might have about my script or some techniques, since I'm kinda new on Python.
Greetins!