Actually, we have a similar broken curve. I want to find an approximating function, and calculate the area under it. I do not want a suggestive answer, it seems, see if there is math or scipy, but references to where there is a similar implementation, or at least. Similar, I am a beginner, and it is impossible to realize this on my own. retention plot

1 answer 1

You can use numpy.trapz ()

Numpy example:

import numpy as np from scipy.integrate import simps from numpy import trapz x = np.linspace(0, 5, 21) y = np.pi / np.exp(x) # dx - растояниС ΠΌΠ΅ΠΆΠ΄Ρƒ сосСдними X ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π°ΠΌΠΈ area = trapz(y, dx=5/20) 

Result:

 In [19]: simps(y, dx=5/20) Out[19]: 3.1204919857832971 In [20]: trapz(y, dx=5/20) Out[20]: 3.1366600769000623 

Schedule:

 In [21]: plt.grid() In [22]: plt.plot(x, y) Out[22]: [<matplotlib.lines.Line2D at 0xd5a5c50>] In [23]: plt.grid() In [24]: plt.savefig('c:/temp/a.png') 

enter image description here