user3368447
user3368447

Reputation: 125

Nested loops in gnuplot and postscript terminal

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)}}

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?

Upvotes: 2

Views: 2947

Answers (1)

Christoph
Christoph

Reputation: 48420

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 ...

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))}}

Upvotes: 3

Related Questions