We can plot the peaks in GNUplot thanks to the answer in this blog (Find local maximum of data files in gnuplot). Here is my script.
xcolumn=1
ycolumn=0
count = 0
plot "test.csv" u (column(xcolumn)):(column(ycolumn)) title "freq" w l, \\
"test.csv" u (column(0)==0 ? (last2y=column(ycolumn), \\
last2x=column(xcolumn), 1/0) : column(0)==1 ? (lasty=column(ycolumn), \\
lastx=column(xcolumn), 1/0) : lastx) \\
: \\
( column(0) < 2 ? 1/0 : (last2y <= lasty && \\
column(ycolumn) < lasty) ? (value=lasty, last2y=lasty, last2x=lastx, \\
count = count +1, \\
lasty=column(ycolumn), lastx=column(xcolumn), value) : (last2y=lasty, \\
last2x=lastx, lasty=column(ycolumn), lastx=column(xcolumn), 1/0)) title sprintf("Peaks %d", count) pt 7
The problem now is to add the value of count to the legnd. I tried at as title sprintf("Peaks %d", count) as shown as the last line of my script given above but it is returning 0. If i do print count after the plot block, it gives 23. How can we add the value of a variable to the legend in GNUplot? Any help would be appreciated.


