I have a list of several pairs. You can find it here or create it manually. Applying ListPlot on the intended list results in the below plot:


How do I extract the maximum pairs (x,y), whose y components are recognizable in the plot, from the list as an individual list.

  • 1
    $\begingroup$ This would seem the be a perfect application for FindPeaks. Have you tried this? $\endgroup$
    – dwa
    Aug 12 '19 at 8:10
  • $\begingroup$ It is a good comment but we reach the positions of peaks and the value of them. We should extract the exact value of the x components in lieu of their positions. $\endgroup$ Aug 12 '19 at 8:17

For finding the position and the values of the peaks:

peakPosValues = Pick[data, PeakDetect[data[[;; , 2]]], 1];

$\left( \begin{array}{cccc} 0.&1.\\ 4.4&0.982211\\ 8.9&0.961575\\ 13.3&0.942571\\ 17.8&0.923857\\ \ 22.2&0.906203\\ 25.1&0.046994 \end{array} \right)$

ListPlot[{data, peakPosValues}, 
 PlotStyle -> {Directive[Blue], Directive[Red, PointSize[0.02]]}]

enter image description here

If you don't want the last "peak" on the bottom right, replace the PeakDetect options as follows:

peakPosValues = Pick[data, PeakDetect[data[[;; , 2]], 1, 0, .8], 1]

You seem to be asking for maxima near the peaks in the data ...

We can find peaks in the data using FindPeaks:

ipeak = Most@FindPeaks[irawd[[All, 2]], .5];
ipeak = irawd[[#]] & /@ ipeak[[All, 1]]

ipeak corresponds to @Fraccolo's answer.

We can find maxima near these peaks after interpolating, then using FindMaximum:

intrp = Interpolation[irawd];
apeak = ipeak;
  v = ipeak[[jp, 1]];
  p = FindMaximum[intrp[t], {t, v}];
  apeak[[jp]] = {t /. p[[2]], p[[1]]},
  {jp, 2, Length@ipeak}

so that apeak are the real peaks. We can compare peaks in the measured data with those in the 'real' function using

tabl = Partition[Flatten@Transpose[{ipeak, apeak}], 4];
 TableHeadings -> {Automatic, {"Data X", "Data Peak", "Interp. X", 
    "Interp. Peak"}}]

enter image description here

Based on the similarity between your data and the underlying function, it would seem that you've sampled things very well.

Graphically ...

iepl = {Red, PointSize[.02], Point[#]} & /@ ipeak;
aepl = {Blue, PointSize[.01], Point[#]} & /@ apeak;
Plot[intrp[t], {t, 0, irawd[[-1, 1]]},
 Epilog -> {iepl, aepl}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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