1

I have a single column file from an oscilloscope that reads voltage versus sample number and I'm wanting to plot the trace in gnuplot and label the two maxima in my signal. The first one is easily found from GPVAL_DATA_Y_MAX, as shown here:

set term png 1 small
set output "~/path/to/outputfile.png"
max_y = GPVAL_DATA_Y_MAX
set label 1 gprintf("Max = %g", max_y) at x, y
plot "~/path/to/myfile" w lines lt rgb "black"

This is a snippet of a larger macro that I've written to plot multiple traces from multiple files simultaneously. I can label my first maximum no sweat, but I can't seem to sort out a good method for labeling the second peak in my data.

6
  • Do you know in which range the maxima appear? Then you could call stats twice with different ranges. In any cases you should use that command to extract values from data. If you don't know the approximate range where the maxima appear you should use e.g. a python script for the calculations. Commented Aug 3, 2016 at 19:02
  • I can do an initial plot of the data to find an approximate range and then adjust that way, I suppose. The issue is that each file has a different range, so I would need to plot each file, then manually adjust the range parameter, which seems inefficient. Commented Aug 3, 2016 at 19:47
  • Yes, this is inefficient. But then the answer is: Use an external script to calculate the maxima positions, gnuplot isn't a numerical tool. You could write e.g. a python script which does the calculations and writes the positions space-separated to stdout. Then, from gnuplot you do something like pos = system("python myscript.py"); and you continue with the values in pos. Commented Aug 3, 2016 at 19:56
  • All right... a python script it is! Thanks for pointing me in the right direction. Commented Aug 3, 2016 at 20:32
  • 1
    I think this is relevant (maybe a duplicate?): stackoverflow.com/questions/28173128/… By the way I agree an external code is better for this task, the linked answer is more of a "curiosity" than anything else. Commented Aug 4, 2016 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.