2
votes

I have a large number of ASCII files named in order of the form data.xxxx.tab, where "xxxx" is a number between 0000 and 9999. Each file contains 5 columns, where the first is for X-coordinate, second is for Y-coordinate and the remaining three are for variables which I wish to plot against X-coordinate. I need to know how to write a loop in gnuplot 4.6, that could plot consecutive graphs of one of the variables against X-coordinate.

I already tried the instructions given in the following posts:

Plotting with gnuplot from several files

and

gnuplot : plotting data from multiple input files in a single graph

but these created a single graph containing all the curves from all the data files together, whereas what I need are consecutive graphs that are plotted one after another, thus showing the evolution in time of the variable graph.

2

2 Answers

2
votes

The following should work:

# fix axes for proper comparison between graphs
set xrange [0:10]
set yrange [0:10]

# if you want an animated gif
set term gif animate
set output 'output.gif'

# then plot your data
do for [n=0:9999]{
    plot sprintf("data.%04d.tab", n) using 1:2 title 'case '.n
}

The %04d string inside the sprintf command prints the number n with until four zeros before the minimum field width of n, i.e. n=2 is printed as 0002, and n=9999 is printed as 9999.

1
votes

I would suggest using a shell script that calls a gnuplot file

file plot.gp:

set term png
set out fname.".png"
set title fname
plot fname w l

and then in the shell:

for fname in data.????.tab; do gnuplot -e fname=\"$i\" plot.gp; done

you'll get a file named data.xxxx.tab.png file for each data.xxxx.tab.