有没有办法在gnuplot上的一个文件中循环数据?

时间:2016-07-01 15:45:21

标签: loops gnuplot

有没有办法循环浏览数据文件并提取特定点以在图表上绘制它们,然后将图像保存在gnuplot上?

例如我的代码到目前为止:

save output 'graph.$n.png'
set label 4 at $x,$y point pointtype 5
plot 'C:\Users\Desktop\testdata.dat' using 2:3 w l

但我希望能够将'x'和'y'更改为数据文件的第二和第三列中的一行中包含的值,然后在行图上将plot更改为,保存图像,然后循环到下一行数据值。有超过100行数据,我想要一种自动化图形化过程的方法。

感谢所有帮助,谢谢!!

格雷斯

2 个答案:

答案 0 :(得分:1)

如果您有awk,请输入终端

awk 'BEGIN{i=1;while(i<100){printf "set term png;set output \"graph.%03d.png\";plot \"testdata.dat\" u 2:3 every 99999::"i"pt 5,\"testdata.dat\" u 2:3 w l;\n",i,i+5;i++}}' > test.plt

这将生成绘图文件“test.plt”,然后打开

gnuplot

并加载绘图文件

load "test.plt"

然后它将生成100个png文件。

示例:如果testdata.dat是sin(x)函数,则会获得100个带序列号的png文件,如下图所示。对于100多个文件,请替换

while(i<100)

具有适当的值。 enter image description here

答案 1 :(得分:1)

我也不知道'单行'解决方案(不使用外部辅助文件),但有一个'prue Gnuplot'解决方案:

stats 'Grace.dat'
n=STATS_records
i=1
load 'hundreds_of_plots.plt'

其中'hundred_of_plots.plt'是:

set term unknown
plot [i-1:i-0.5] 'Grace.dat' u 0:2
labelx=GPVAL_DATA_Y_MAX
plot [i-1:i-0.5] 'Grace.dat' u 0:3
labely=GPVAL_DATA_Y_MAX
set label 4 at labelx,labely point pointtype 5
set term png
set output "".i.'.png'
plot 'Grace.dat' u 2:3 w l
i=i+1
set output "".i.'.png'
if (i<=n) reread