[英]How to add time dependent labels in Gnuplot
一个数据文件包含三列,第一列和第二列分别代表第三列给出的时间(以秒为单位)的圆的 x 和 y position。 例如,“data.txt”中的前两行给出时间=0 时两个圆的 position,然后是两个空行,然后是时间=0.1 秒时两个圆的 position,依此类推。 data.txt 的前几行是:
0 0 0
-1 -1 0
1 1.0 0.1
-1 -0.5 0.1
1.2 1.25 0.2
-0.5 -0.25 0.2
...
生成一系列帧(电影)的 Gnuplot 代码与两个圆圈的 position 在时间上是:
set terminal gif size 1200,1200 animate delay 500
set output "movie.gif"
stats "data.txt" u 1:2 name "A"
set style circle radius graph 0.025; set style fill solid
set xrange [A_min_x*1.1:A_max_x*1.1]
set yrange [A_min_y*1.1:A_max_y*1.1]
do for [i=0:A_blocks-2] {
plot "data.txt" index i u 1:2 w circle
}
我正在尝试添加 label 或“时间=?”形式的文本框到问号被第三列中的数字替换的每一帧。 关于如何做的任何建议?
这个答案需要当前版本的 gnuplot (5.4)
假设给定数据块中的所有第 3 列条目都相同,那么说
plot "data.txt" index i u 1:(FOO=strcol(3),column(2)) w circle title sprintf("Time = %s",FOO)
这会更新每行使用的 FOO 的值。 标题使用了 plot 的最终更新。 如果您必须从块中的特定行中专门选择第 3 列的值,或者计算平均值,这是一个更难的问题。 在这种情况下,请澄清。
我想到的第一个(不太明显)解决方案: plot 循环中的数据并将第三列的值分配给变量,例如t
。 使用 keyenty 打印图例,同时重新使用变量t
。 为了避免图例中出现符号,请使用with points
的绘图样式和点大小为 0 的点。
代码:
### animation with time label
reset session
$Data <<EOD
0 0 0
-1 -1 0
1 1.0 0.1
-1 -0.5 0.1
1.2 1.25 0.2
-0.5 -0.25 0.2
EOD
set terminal gif size 400,400 animate delay 100
set output "SO70474478.gif"
stats $Data u 1:2 name "A" nooutput
set style circle radius graph 0.025; set style fill solid
set xrange [A_min_x*1.1:A_max_x*1.1]
set yrange [A_min_y*1.1:A_max_y*1.1]
set key top left
do for [i=0:A_blocks-1] {
plot $Data index i u 1:(t=$3,$2) w circle notitle, \
keyentry w points ps 0 ti sprintf("Time: %.1f",t)
}
set output
### end of code
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.