gnuplot和postscript终端中的嵌套循环 [英] Nested loops in gnuplot and postscript terminal
问题描述
我在带有postscript eps终端的gnuplot上使用,这是我的脚本:
I am using gnuplot with the postscript eps terminal, this is my script:
set terminal postscript eps enhanced solid "Helvetica" 14
set output "gamma_off_real.ps"
set title 'L=4, N_{up}=N_{dw}=2, U=1.0 with HF, step, V_0=1, Ntimestep=400, Tinterval=10'
set xlabel 'time'
set ylabel 'Re({/Symbol g}_{ij})'
set yrange [-0.5:1]
do for [j=1:(nsit-1)] {do for [i=1:(nsit-j)] {plot 'time/fort.99' u (column(1)):(column((i-1)*nsit+i+j+1)) w l lt 1 lc ((-((j-1)*j)/2+(j-1)*nsit)+i+nsit) lw 3 t sprintf('Re({/Symbol g}_{%i%i})',i,i+j)}}
我在.ps文件的末尾使用两个嵌套的for循环,我有多个页面,每个页面只有一条曲线.为了使所有曲线都在同一图中,我应该改变什么?
I use a two nested for loops by at the end in my .ps file I have more than one pages each with only one curve. What should I change to have all the curves in the same plot?
推荐答案
您必须使用语法plot for ...
,该语法也可以嵌套:
You must use the syntax plot for ...
, which can also be nested:
plot for [j=1:(nsit-1)] for [i=1:(nsit-j)] 'time/fort.99' u ...
更新:这不起作用,在plot for ... for
结构中,第二个索引不能依赖第一个索引.以下仅绘制了三条曲线,而不是六条:
Update: this doesn't work, in the plot for ... for
structure the second index cannot depend on the first one. The following plots only three curves instead of six:
plot for [j=1:3] for [i=1:j] i*x + j
有些丑陋的东西可能会起作用:
Some very ugly like the following could work:
s = ''
do for [j=1:(nsit-1)] { do for [i=1:(nsit-j)] { s = s . sprintf('%d %d ', i, j) }}
i(w) = int(word(s, 2*w - 1))
j(w) = int(word(s, 2*w))
plot for [w=1:words(s)/2] 'time/fort.99' u (column(1)):(column((i(w)-1)*nsit+i(w)+j(w)+1)) w l lt 1 lc ((-((j(w)-1)*j(w))/2+(j(w)-1)*nsit)+i(w)+nsit) lw 3 t sprintf('Re({/Symbol g}_{%i%i})',i(w),i(w)+j(w))}}
这篇关于gnuplot和postscript终端中的嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!