2

Given a plot in matplotlib, how to find the area covered by them(integrated area)?

enter image description here

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41

2 Answers2

3

use shapely

here's a quick rundown in a different QA

>>> from shapely.geometry import Point
>>> a = Point(1, 1).buffer(1.5)
>>> b = Point(2, 1).buffer(1.5)
>>> c = a.intersection(b)
>>> c.area
4.11619859013966
vencaslac
  • 2,727
  • 1
  • 18
  • 29
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/21331672) – Mehdi Nov 05 '18 at 18:15
  • 2
    added example from the refferenced QA – vencaslac Nov 05 '18 at 19:37
0

If you have x, y points I assume that you are working on a discreate function rather than continious function. If you are sure that there will be only 2 point respect to x axis you can sum difference of the y axis.

import numpy as np 

point_list = np.array([(1, 3), [1, 5], (2, 3), (2 ,10)])
_sum = 0
for point in point_list:
    indexes = np.where([points[0] for points in point_list] == point[0])[0]
    _sum += abs(point_list[indexes[0]][1] - point_list[indexes[1]][1]) / 2
print(_sum)