|
From: theozh <th...@gm...> - 2018-10-18 18:45:32
|
Hi,
I would like to find the x-value of some data when its y-value passes a certain threshold.
The curves can be very different, so I think that fitting to a certain function is probably not a solution.
I know gnuplot is probably not made for that and other tools should be used. However, sometimes it is very convenient if there is a pure gnuplot solution.
The basic idea is:
Subtracting the threshold from the data, take the square of this and look for the minimum.
Maybe, I am trying way too complicated? If there are better ways please let me know.
Thanks, Theo.
The following sample generates some simple dummy data to illustrate.
### finding thresholds with gnuplot
reset
# generate some dummy data
set print $Data
do for [i=1:100] {
print sprintf("%g %.3f",i*2+rand(0), rand(0)*10+i)
}
set print
print $Data
THRESHOLD = 60
# $Data2 holds (difference to threshold) squared
set table $Dummy
plot $Data u 1:(($2-THRESHOLD)**2) with table
unset table
# find minimum with stats
stats $Data2 u 1:2 nooutput
MINIMUM = STATS_index_min_y
# find x and y value of $Data
set table $Dummy
plot $Data u (MIN_X = $1,1):(MIN_Y=$2,$2) every ::MINIMUM::MINIMUM with table
unset table
set key top left
set multiplot layout 2,1
set label 1 sprintf("Value %g at %g",MIN_Y, MIN_X) at graph 0.5, graph 0.9
set arrow 1 from first MIN_X, graph 0 to first MIN_X, THRESHOLD
unset logscale y
plot $Data u 1:2, THRESHOLD w l
set logscale y
plot $Data2 u 1:2 w l
unset multiplot
### end gnuplot code
|