Find the area between two curves plotted in matplotlib (fill_between area)

后端 未结 5 1240
生来不讨喜
生来不讨喜 2020-12-08 08:39

I have a list of x and y values for two curves, both having weird shapes, and I don\'t have a function for any of them. I need to do two things: (1) plot it and shade the ar

5条回答
  •  自闭症患者
    2020-12-08 08:45

    Define your two curves as functions f and g that are linear by segment, e.g. between x1 and x2, f(x) = f(x1) + ((x-x1)/(x2-x1))*(f(x2)-f(x1)). Define h(x)=abs(g(x)-f(x)). Then use scipy.integrate.quad to integrate h.

    That way you don't need to bother about the intersections. It will do the "trapeze summing" suggested by ch41rmn automatically.

提交回复
热议问题