# How to calculate the area of a listplot [duplicate]

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: Any help would be appreciated, thank you in advance.

• 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

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.

• 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