Given a plot in matplotlib, how to find the area covered by them(integrated area)?
Asked
Active
Viewed 2,104 times
2

Valdi_Bo
- 30,023
- 4
- 23
- 41

Dipankar Saha
- 31
- 3
-
1what function gives you that graph? – dejanmarich Nov 05 '18 at 14:23
-
1If you have the functions to plot the graphs, then you can probably derive an analytical (i.e. exact) solution. Otherwise, you'll need to settle for a numerical approximation using something like the Trapezoidal Rule (https://en.wikipedia.org/wiki/Trapezoidal_rule) or something more sophisticated. – DatHydroGuy Nov 05 '18 at 14:33
-
1This is a measured data. hence I do not have any function. I am trying with integ.trapz – Dipankar Saha Nov 05 '18 at 14:45
-
Do you have the underlying data points, or just the graph? :) – NPE Nov 05 '18 at 14:51
-
You can easily calculate areas of arbitrary polygons with shapely – Martin Thoma Nov 05 '18 at 15:08
-
@NPE I have the data points – Dipankar Saha Nov 06 '18 at 08:32
-
@Martin Thank you – Dipankar Saha Nov 06 '18 at 08:33
2 Answers
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
-
1While 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
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)

İhsan Cemil Çiçek
- 191
- 12