Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 = 
MorphologicalComponents[
 Erosion[Binarize[
   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.

share|improve this question
    
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... –  BoLe May 29 '13 at 16:13
    
When you say it's not a polygon, do you mean the lines overlap? Or that it is not closed? –  Michael E2 May 29 '13 at 17:09
    
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 –  John May 29 '13 at 17:12
    
Related answer -- assumes no self-intersections. –  Michael E2 May 29 '13 at 17:15
    
Another related question - actually I'm now pretty sure that this is a duplicate of the linked question. –  Jens May 29 '13 at 17:21
show 1 more comment

marked as duplicate by Jens, J. M. May 29 '13 at 17:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

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]];

Integrate[
 Interpolation[list, InterpolationOrder -> 1][x], {x, 1, 
  Length[list]}]

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.

share|improve this answer
    
I can't use an interpolating function because it is a cicle and some x values have more than one correspondant y value –  John May 29 '13 at 16:56
    
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. –  Jens May 29 '13 at 17:17
add comment

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