I need to calculate the area enclosed in a two-dimensional listplot and following an answer to a similar question I tried this way:

imgnorm = (mnorm = 
   ListLinePlot[{list}, ImageSize -> Large, Axes -> False]], 
  0.5]]) // Colorize

listareas = {area1 = 1/. ComponentMeasurements[{mnorm, imgnorm}, "Area"], area2 = 2/. ComponentMeasurements[{mnorm, imgnorm}, "Area"]}

It works fine, however it is not precise enough for what I need to do because part of the area is taken by the black line.

The list is quite big and the points don't form a polygon.

EDIT: Here is the plot:

list plot

Any help would be appreciated, thank you in advance.

  • $\begingroup$ Can you show the list resoluted-down perhaps? And could you close it to form a polygon for any practical purpose? For we know how to compute the polygon area... $\endgroup$ – BoLe May 29 '13 at 16:13
  • $\begingroup$ When you say it's not a polygon, do you mean the lines overlap? Or that it is not closed? $\endgroup$ – Michael E2 May 29 '13 at 17:09
  • $\begingroup$ It is closed but the lines overlap, it wouldn't be a problem to remove those points if I could do it automatically, I don't need to be that precise $\endgroup$ – John May 29 '13 at 17:12
  • $\begingroup$ Related answer -- assumes no self-intersections. $\endgroup$ – Michael E2 May 29 '13 at 17:15
  • $\begingroup$ Another related question - actually I'm now pretty sure that this is a duplicate of the linked question. $\endgroup$ – Jens May 29 '13 at 17:21

I don't see any reason to create a plot at all. According to your example, you have a list that can be plotted with ListLinePlot. That means it can be interpolated by a piecewise linear function. Consequently, you only need to find that linear function and calculate its integral.

Here is an example:

list = Accumulate[RandomReal[{-1, 1}, 250]];

 Interpolation[list, InterpolationOrder -> 1][x], {x, 1, 

This assumed that the x axis runs from 1 to the length of the list. It's easy to extend this to cases where the scale is different, or the x axis values are not evenly spaced.

The important ingredient is InterpolationOrder. The setting 1 leads to a linear interpolation the way it is plotted in ListLinePlot. Higher settings would produce smoothed approximations that may or may not be a better representation of the data you're trying to integrate.

| improve this answer | |
  • $\begingroup$ I can't use an interpolating function because it is a cicle and some x values have more than one correspondant y value $\endgroup$ – John May 29 '13 at 16:56
  • $\begingroup$ I see. But then it will still be possible to divide your list into separate parts that can be considered functions over an interval on the horizontal axis. I'd say that's much more efficient than to try and extract the same information from a plot of any kind. Plotting is just a detour if you already have the data. $\endgroup$ – Jens May 29 '13 at 17:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.