【问题标题】:GNUPLOT: stats gives wrong results on loopGNUPLOT:统计数据在循环中给出错误的结果
【发布时间】:2016-02-03 00:26:22
【问题描述】:

我有一个数据文件,其中矩阵拆分为不同的 gnuplot 索引。我想做一个密度图随时间变化的动画(=index)。

问题是我想保持 cbrange 的最大值和最小值对称,同时允许它随时间变化。

在下面的代码中,第一个“stats”命令只是给了我循环的块数。第二个带有前缀“B”的“stats”命令应该给我每个索引处矩阵的最大值和最小值,所以我可以正确设置 cbrange。

代码第一次进入循环时它会起作用(对于 i=1),并且 stats 会为我提供正确的数字。从第二个循环开始 (i=2) stats 给了我错误的数字...

我尝试在 stats 命令之前将 cbrangezrange 设置为 [*:*],但没有帮助。

代码如下:

set terminal gif animate delay 0.5
set output 'foobar.gif'
stats 'dat-rw2d.dat' nooutput

set pm3d map
set palette defined (-1 "blue", 0 "white", 1 "red")

print STATS_blocks

do for [i=1:int(STATS_blocks)] {
    print i

    stats "dat-rw2d.dat" index (i-1) matrix nooutput prefix "B"

    max = (B_max > -B_min)?(B_max):(-B_min)
    set cbrange [-max:max]

    print B_max, B_min

    splot 'dat-rw2d.dat' matrix index (i-1)
}

如果我不绘制任何东西(下面的代码),统计数据会给我正确的数字。所以实际上是导致问题的“splot”。它正在修复一些规模并妨碍统计数据?我试过在统计前set cbrange [*:*],但它并没有解决问题。

do for [i=1:int(STATS_blocks)] {
    print i

    stats "dat-rw2d.dat" index (i-1) matrix nooutput prefix "B"

    max = (B_max > -B_min)?(B_max):(-B_min)
    set cbrange [-max:max]

    print B_max, B_min
}

【问题讨论】:

  • 会在splot 帮助之后添加set cbrange [*:*] 吗?
  • 我试过set cbrange [*:*],但它不起作用。我也在其他地方读过这个技巧......但它不起作用。
  • help xrange(适用于所有范围)中,它表示您需要一个星号来进行自动缩放。
  • 我知道用于自动缩放的星号。问题是即使强制执行自动缩放,statssplot 命令之后仍然给出错误答案。这似乎是一个真正的错误。
  • 对我来说它看起来像一个 gnuplot 错误,我什至尝试添加一个 reset,但它仍然失败

标签: gnuplot


【解决方案1】:

如果您没有为stats 指定任何列,gnuplot 会尝试猜测一个合适的默认列。使用matrix 选项,这似乎是一个错误的选项(可能是 x 值或 y 值,或矩阵大小),它不会因块而异。

您必须告诉 gnuplot 明确地将第三列用于 stats

stats 'dat-rw2d.dat' nooutput

set pm3d map
set palette defined (-1 "blue", 0 "white", 1 "red")

print STATS_blocks

do for [i=1:int(STATS_blocks)] {
    print i

    stats "dat-rw2d.dat" using 3 index (i-1) matrix nooutput prefix "B"

    max = (B_max > -B_min)?(B_max):(-B_min)
    set cbrange [-max:max]

    print B_max, B_min

    splot 'dat-rw2d.dat' matrix index (i-1)
}

【讨论】:

  • 谢谢,它正在工作......但是 gnuplot 文档有问题。在help stats 中可以看到:“当指定matrix 时,using 选项被忽略,“z”值被视为一维数据集。”
【解决方案2】:

由于它看起来像一个错误,我只能提出一个解决方法(恕我直言),但这就是我想到的:

system 命令中调用gnuplot,将变量保存在文件dummy.txt 中并从您的脚本中加载该文件。

stats 'test.txt' nooutput
do for [cntr=1:int(STATS_blocks)] {

    # next line doesn't work 
    # stats 'test.txt' index (cntr-1) matrix prefix "B"

    # next 3 lines do the hack
    cmd=sprintf('gnuplot -e "stats \"test.txt\" index %d matrix nooutput prefix \"B\"; save var \"dummy.txt\""',cntr-1)
    system(cmd)
    load("dummy.txt")

    print cntr, B_max, B_min
    max = (B_max > -B_min)?(B_max):(-B_min)
    set cbrange [-max:max]

    splot 'test.txt' matrix index (cntr-1) w l
}

如果有人愿意重现问题,这是我的test.txt 文件:

0 0 
0 1 


1 1 
1 2 


2 2 
3 3 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-22
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2012-09-01
    • 1970-01-01
    • 2013-01-13
    相关资源
    最近更新 更多