如何在Gnuplot中打印多个函数的最大值

时间:2014-05-06 05:18:36

标签: max gnuplot

我的问题很基本。我正在使用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

1 个答案:

答案 0 :(得分:2)

您可以使用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才能获得最大y值所在的x值:

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

不幸的是,大多数命令都无法通过更改变量名来正确迭代。