【问题标题】:Gnuplot find local maximum of 3D dataGnuplot 查找 3D 数据的局部最大值
【发布时间】:2017-04-02 20:45:30
【问题描述】:

我在 gnuplot 中遇到问题...

我正在从 1、1/2、1/3 等 y 值中离散的“线”(见附图)的数据点制作一个 splot... 在每条离散的“线”上,我想获得最大的 Z 值及其 X 和 Y 坐标,并突出显示它们,或者可能在它们上拟合一个函数等......

这是我的代码:

set title "1/m vs mutation rate"
#set term pdfcairo size 6,4
set term x11

set xlabel "Mutation rate"
set ylabel "1/m"

set xrange[0.0001:0.05]
set yrange[1.0/30:1]
unset log x

set cbrange[0:0.35]
set zrange[0:1]
set palette defined ( 0 "green", 1 "blue", 2 "red") 

#set view 78,348,1,1
set view map

set output "muemmeres500map.pdf"

splot 'muemmeres500.txt' u 1:2:3  with points pt 5 ps 1 palette, "muemmeres500.txt" every 30 using ($3==GPVAL_DATA_Z_MAX?$1:NaN):($3==GPVAL_DATA_Z_MAX?$2:NaN):3 title "max1" lc rgb'black' lw 4, "muemmeres500.txt" every 30::2 using ($3==GPVAL_DATA_Z_MAX?$1:NaN):($3==GPVAL_DATA_Z_MAX?$2:NaN):3 title "max2" lc rgb'black' lw 4, "muemmeres500.txt" every 30::3 using ($3==GPVAL_DATA_Z_MAX?$1:NaN):($3==GPVAL_DATA_Z_MAX?$2:NaN):3 title "max3" lc rgb'black' lw 4, "muemmeres500.txt" every 30::4 using ($3==GPVAL_DATA_Z_MAX?$1:NaN):($3==GPVAL_DATA_Z_MAX?$2:NaN):3 title "max4" lc rgb'black' lw 4, "muemmeres500.txt" every 30::5 using ($3==GPVAL_DATA_Z_MAX?$1:NaN):($3==GPVAL_DATA_Z_MAX?$2:NaN):3 title "max5" lc rgb'black' lw 4

unset output

这里是数据文件:http://pastebin.com/umqGWtyy

正如您在图片中看到的,“lines”数据点对应于数据文件中的每一行,因此例如从第一个然后每 30 个开始的数据点对应于值为 1 的“line”,然后从第二行开始,每 30 对应 y 值为 1/2 等的“行”...

因此,我想从这些数据中获取最大 Z 值...

我也尝试过 sed,但失败了...

所以我的问题是,它只能找到全局最大值而不是其他局部最大值...:(请帮助我:)

这是图片:

我不知道...希望我的英语可以理解和抱歉...:)

【问题讨论】:

    标签: sed find max gnuplot


    【解决方案1】:

    GPVAL_DATA_Z_MAX 似乎不适用于您的问题,但您可以使用 stats 来查找所有局部最大值,然后将它们全部绘制在一个循环图中。

    #Do it before setting the ranges (the column will be handled as an x column and it might get out of xrange)
    do for [i=0:28]{
      #Give an indexed prefix to each stat (so they *all* become accessible from outside the loop, like "A12_max" or "A25_min")
      stats 'muemmeres500.txt' every 30::i u 3 nooutput prefix "A".i
    }
    
    #set all the things you need for the plot (including ranges)
    ...
    
    splot 'muemmeres500.txt' u 1:2:3  with points pt 5 ps 1 palette, \
          for [i=0:28] '' every 30::i u 1:2:($3==value("A".i."_max") ? $3 : NaN) notitle #t "Max".(i+1)
    

    注意:every使用的索引从零开始。

    这仅适用于绘图,您拥有所有最大值,但您还没有 X 和 Y 坐标。

    您还拥有最大值的索引,因此如果您可以从 A<n>_index_max 行(实际上是它的 30*index+i 或第 n 个块的第 i 行)检索 X Y 值,那么您将获得第 n 个最大位置。要检索第 n 行,您可以再次使用 statsevery

    do for [i=0:28]{
      stats 'muemmeres500.txt' every ::i:value("A".i."_index_max"):i:value("A".i."_index_max") u 1:2 nooutput prefix "P".i
    }
    

    如果您在获得 Ai_ 统计数据后立即执行此操作,则您已经拥有所有位置 P<i>_max_x P<i>_max_y 和 Z 值 A<i>_max

    如果您愿意,可以将它们打印到文件中:

    set print "maxima.dat"
    do for [i=0:28]{
      print value("P".i."_max_x"), (value("P".i."_max_y")), (value("A".i."_max"))
    }
    unset print
    

    【讨论】:

      猜你喜欢
      • 2018-08-10
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多