# How to construct and plot the following accumulated list?

I have a list, say it is

a = {1,3,3.2,3.9,4,4.4,4.9,5,7,8}


To get the accumulate:

acc = Accumlate[a]


I want to plot the number of elements less than or equal to a certain element against the accumulated value of the list elements. The pairs should look like (acc[[i]], number of elements less than a[[i]]). For instance, (1, 1), (4, 2), (7.2,3), etc.

Then I want to take the derivative of the plot to plot it as well.

• The plotting is not a problem see ListPlot. Also, if you want a derivative you will have to define this as you don't have a continuous function. What have you tried so far? – Hugh Apr 13 at 11:26
• The plot is an issue when I have very large number of pairs like 1000 pairs. I am trying to do it using ListPlot and a Do loop but it does not work. I am doing: ListLinePlot[{Do[Print[{acc[[i]], Count[a[[i]]}], {i, 10}]}] but it only prints the pairs for me with an empty plot. – Hamza Apr 13 at 12:04
• Your combined use of Do and Print doesn't do what you expect. Print merely prints to the screen but does not build a list; use Table instead. Also, Count is something else. – Roman Apr 13 at 16:29

Assuming that there are no duplicate elements in the list, and that the list is sorted in ascending order:

ListLinePlot[Transpose[{Accumulate[a], Range[Length[a]]}]]


If the list isn't sorted, you should replace Accumulate[a] with Accumulate[Sort[a]].

If you need the derivative, it may be easier to first construct an interpolating function. Here I make the interpolation linear (InterpolationOrder -> 1) but you can change this. You can get the above plot with Plot[b[x], {x, 1, Total[a]}] and the first-derivative plot with

b = Interpolation[Transpose[{Accumulate[Sort[a]], Range[Length[a]]}],
InterpolationOrder -> 1];
Plot[b'[x], {x, 1, Total[a]}]


try this

a = {1, 3, 3.2, 3.9, 4, 4.4, 4.9, 5, 7, 8};
acc = Accumulate@a;
aa[x_] := Length@Select[a, # <= a[[x]] &];
list = Transpose[{acc, aa /@ Range@Length@a}]
ListLinePlot@list


{{1,1},{4,2},{7.2,3},{11.1,4},{15.1,5},{19.5,6},{24.4,7},{29.4,8},{36.4,9},{44.4,10}}

• The y-axis should represent the number of elements less than or equal a[[i]] not the element itself. – Hamza Apr 13 at 13:57
• @Hamza fixed.... – J42161217 Apr 13 at 14:12