我的问题很基本。我使用gnuplot一次绘制多个函数,并且我想打印出(在文件中或在图形本身上)每个函数的最大y值。知道我该怎么做吗?
我研究了STATS和GPVAL_DATA_Y_MAX,但我真的无法弄清楚如何使它们同时使用多个功能。
无需过多讨论,让我们假设我的文件如下所示:
plot 'file1.dat' us 1:2 title "file1" w lines,\
'file2.dat' us 1:2 title "file2" w lines,\
'file3.dat' us 1:2 title "file3" w lines
您可以使用选项的name
参数stats
将每个文件的最大值保存在一组不同的变量中:
stats 'file1.dat' using 2 nooutput name 'file1'
stats 'file2.dat' using 2 nooutput name 'file2'
stats 'file3.dat' using 2 nooutput name 'file3'
现在您可以将值打印到外部文件中
set print 'max.dat'
print file1_max
print file2_max
print file3_max
如果要在图形中的最大值附近放置相应的标签,则还必须知道数据具有最大值的相应x值。从第一个stats
命令不容易获得此数据,只能从数据文件中找到它的索引。因此,您需要额外调用以stats
获得x值,其中最大y值是:
stats 'file1.dat' using 1 every ::file1_index_max::file1_index_max name 'file1_x'
...
然后您可以使用
set label center at first file1_x_max,first file1_max sprintf('y = %.2f', file1_max) offset char 0,1
不幸的是,大多数命令不能通过更改变量名来正确地迭代。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句