有没有办法迭代检索多个文件中的数据,并将它们绘制在gnuplot中的相同图形上.假设我有像data1.txt,data2.txt ...... data1000.txt这样的文件; 每个都有相同的列数.现在我可以写一些像 -
plot "data1.txt" using 1:2 title "Flow 1", \
"data2.txt" using 1:2 title "Flow 2", \
.
.
.
"data1000.txt" using 1:2 title "Flow 6"
Run Code Online (Sandbox Code Playgroud)
但这真的很不方便.我想知道是否有办法循环通过gnuplot中的情节部分.
and*_*ras 91
肯定是(在gnuplot 4.4+中):
plot for [i=1:1000] 'data'.i.'.txt' using 1:2 title 'Flow '.i
Run Code Online (Sandbox Code Playgroud)
变量i
可以解释为变量或字符串,因此您可以执行类似的操作
plot for [i=1:1000] 'data'.i.'.txt' using 1:($2+i) title 'Flow '.i
Run Code Online (Sandbox Code Playgroud)
如果你想让线条相互偏移.
键入help iteration
gnuplot命令行以获取更多信息.
另外一定要看看@DarioP关于do for
语法的答案; 这使您更接近传统的for
循环.
Dar*_*ioP 79
do { ... }
从gnuplot 4.6开始看一下命令,因为它非常强大:
do for [t=0:50] {
outfile = sprintf('animation/bessel%03.0f.png',t)
set output outfile
splot u*sin(v),u*cos(v),bessel(u,t/50.0) w pm3d ls 1
}
Run Code Online (Sandbox Code Playgroud)
http://www.gnuplotting.org/gnuplot-4-6-do/
Jon*_*röm 10
我有脚本all.p
set ...
...
list=system('ls -1B *.dat')
plot for [file in list] file w l u 1:2 t file
Run Code Online (Sandbox Code Playgroud)
这里最后两行是文字的,而不是启发式的.然后我跑了
$ gnuplot -p all.p
Run Code Online (Sandbox Code Playgroud)
更改*.dat
为您拥有的文件类型,或添加文件类型.
下一步:添加到〜/ .bashrc这一行
alias p='gnuplot -p ~/./all.p'
Run Code Online (Sandbox Code Playgroud)
并将您的文件放在您all.p
的主目录中,瞧.您可以通过键入p并输入来绘制任何目录中的所有文件.
编辑我改变了命令,因为它不起作用.以前它包含list(i)=word(system(ls -1B *.dat),i)
.
如果您有离散列要绘制在图形中,请使用以下内容
do for [indx in "2 3 7 8"] {
column = indx + 0
plot ifile using 1:column ;
}
Run Code Online (Sandbox Code Playgroud)