从单个数据文件绘制 GIF

Ploting a GIF from a single data file

大家好,我是 gnuplot 的新手,我想绘制一个 gif 来表示某些概率随周期的演变。 我的数据文件结构如下:

0   0   1   3.56133e-008    2   1.18619e-007    3   3.75373e-007 ...
0   0   1   3.56133e-008    2   2.26246e-008    3   1.44814e-007 ...

第一行代表循环0,第一列和第二列代表位置0及其概率。仓位数量多,手动操作太费时间

我现在知道了,但我真的不知道如何用这种数据做 for 循环。

set terminal gif 
set output 'Probability.gif'
stats 'Probability.txt' nooutput
set xlabel 'Position'
set ylabel 'Probability'
set yrange [0:1]
set style fill solid border -1
unset key

在此先感谢您的帮助。

您可以做的是从每一行中提取所有 x 和 y 对并将其绘制到 table 中。实际上,gnuplot 更喜欢将数据放在列中。然后使用选项 animated 将此 table 绘制到 gif 终端。检查 help gif。如果您有一个文件,请删除数据块 $Data <<EOD ... EOD 并在代码中将 $Data 替换(2 次)为 "YourFilename".

代码:

### animated rows x0 y0 x1 y1 x2 y2
reset session

$Data <<EOD
0 0.00   1 0.10   2 0.20   3 0.40   4 0.20   5 0.10   6 0.00
0 0.00   1 0.08   2 0.18   3 0.48   4 0.18   5 0.08   6 0.00
0 0.00   1 0.05   2 0.16   3 0.58   4 0.16   5 0.05   6 0.00
0 0.00   1 0.08   2 0.18   3 0.48   4 0.18   5 0.08   6 0.00
0 0.00   1 0.10   2 0.20   3 0.40   4 0.20   5 0.10   6 0.00
EOD

stats $Data nooutput
ColCount = STATS_columns
RowCount = STATS_records

set xrange[0:6]
set yrange[0:1]

set terminal gif size 400,400 animate delay 50 optimize
set output "myAnimation.gif"

do for [j=0:RowCount-1] {
    set table $Extract
        plot for [i=1:ColCount/2] $Data u (column(2*i-1)):(column(2*i)) every ::j::j w table
    unset table
    plot $Extract u 1:2 w lp pt 7 lw 2 title sprintf("Row %d",j)
}
set output
### end of code

结果: