问题
I have three data files each with a matrix; I use stats to find the maximum value in the matrix for each file and it is displayed correctly. I need to use those three maximum values as data points and plot them so as to have points on my plot as (1.0, A_max), (2.0, B_max) and (3.0, C_max) where A_max is the maximum value calculated using stats from first data file, B_max from second and C_max from third. Here is how my gp file looks like :
set terminal epslatex size 3.5,2.62 color colortext
set output 'data.tex'
set xlabel '$x$'
set ylabel '$y$'
stats 'dataA.txt' matrix name "A"
show variables A_
stats 'dataB.txt' matrix name "B"
show variables B_
stats 'dataC.txt' matrix name "C"
show variables C_
plot '-' w p, '-' w p, '-' w p
1.0 A_max
e
2.0 B_max
e
3.0 C_max
e
The plot I get, looks like below.
Clearly, it is taking x-axis as 0 and the points I intend for my x-axis corresponding to y. Not sure what I am missing, probably how to read the stats variable. Any help will be appreciated.
回答1:
Inline data, like you are using, is used as-is without any variable replacement.
Use set print $data
to print data to the named data block $data
:
set print $data
stats 'dataA.txt' matrix name "A"
print sprintf("%e A", A_max)
stats 'dataB.txt' matrix name "B"
print sprintf("%e B", B_max)
stats 'dataC.txt' matrix name "C"
print sprintf("%e C", C_max)
plot $data using 0:1:xticlabel(2) w p notitle
or, with more automation:
set print $data
do for [f in "A B C"]{
stats 'data'.f.'.txt' matrix name f
print sprintf("%e %s", value(f.'_max), f)
}
plot $data using 0:1:xticlabel(2) w p notitle
来源:https://stackoverflow.com/questions/49325676/gnuplot-using-a-stats-output-as-a-data-point