I am trying to find the inflexion points on a curve using python. The data for the curve is here: https://www.dropbox.com/s/rig8frgewde8i5n/fitted.txt?dl=0. Please note that the curve has been fitted to the raw data. Raw data is available here: https://www.dropbox.com/s/1lskykdi1ia1lu7/ww.txt?dl=0
import numpy as np
# Read in array from text file
arr = np.loadtxt(path_to_file)
inflexion_point_1 = np.diff(arr).argmin()
inflexion_point_2 = np.diff(arr).argmax()
These 2 inflexion points are shows as red lines in the attached plot. However, their locations do not seem to be right. The first inflexion point should be close to the area indicated by the black arrow. How do I fix this?
Also, here is a plot of the differential:
plt.axvline(np.gradient(arr[:365]).argmax())
As you can see, the code is behaving as coded i.e. it finds the argmax of np.diff of the array. However, I want to find a position closer to day 110 or so, i.e. about half-way to argmax.
--EDIT--
Also, here is another plot showing thee raw data and the fitted curve (using a quadratic function).
Any reason not to use uni-variate spline directly on the gradient?
Also we can solve for the maximum numerically: