0
votes

i want to plot datafiles named "0.txt", "1.txt", "2.txt" etc.

My plot-script looks like this:

do for [i=0:9]{

set xrange [-0.5:7.5]

set yrange [-0.5:7.5]

set term pngcairo size 1280,720

set output .i.".png"

plot .i.".txt" matrix with image

set term x11

}

Where .i. is a placeholder for i, which starts at 0 and increases to 9. The error message is: "line 8: Invalid expression"

Do you see the mistake or have an idea?

2

2 Answers

1
votes

Use sprintf to format your string:

set xrange [-0.5:7.5]
set yrange [-0.5:7.5]
set term pngcairo size 1280,720

do for [i=0:9] {
    set output sprintf("%d.png", i)
    plot sprintf("%d.txt", i) matrix with image
}
0
votes

First of all, you should remove set term x11, you need to set your terminal only once. Second, move all constant parameters outside the loop -- they don't change at all.

I use similar gnuplot files, however, I use another external script which provides a set of input values. I have pretty much the same commands for filenames and it works perfectly. For some reason your version doesn't behave like this, so I modified it a bit:

set term pngcairo size 1280,720
set xrange [-0.5:7.5]
set yrange [-0.5:7.5]
do for [i=0:9]{
  set output "".i.".png"
  plot "".i.".txt" matrix with image
}

I've tested it (gnuplot 5.2 patchlevel 4), it generates some desired output correctly.