2

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.

Community
  • 1
  • 1

2 Answers2

2

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.

vagoberto
  • 2,372
  • 20
  • 30
  • Thank you so much! Your suggestion worked well. If it is not a bother, I wish to know whether this method would work the same for .flt or .dbl files in the same way as for .tab data files? – Meir Zeilig-Hess Jan 07 '16 at 15:34
  • What is the difference between tab, flt and dbl files? Those aren't standard file extensions. – Christoph Jan 07 '16 at 16:26
  • @MeirZeilig-Hess I don't know what those file extensions are, but this method should work for any file extension and any ascii file containing columns of data. – vagoberto Jan 07 '16 at 18:26
  • The .flt is single precision (4 byte) binary data file, whereas .dbl is double precision (8 byte) binary data file. In both cases the data can be ordered in columns, similar to the .tab ASCII files. – Meir Zeilig-Hess Jan 07 '16 at 18:35
  • 1
    For binary data, add the `binary` specifier after the filename: `plot sprintf(...) binary format="%5double" using 1:2`. The `%5double` tells gnuplot that the data is formatted in five columns of doubles. – vagoberto Jan 07 '16 at 18:47
  • The last advice really helped (only without the '5' in 'format="%5double"'). One last question, if I may - I tried to carry out the same procedure for making a 2D plot with the gnuplot function 'splot' and by adjusting the 'binary array' from 200:1 to 200:200. No other thing was changed. Nevertheless, I received an error message saying: 'Too many columns in using specification and implied sampling array'. What can I do to overcome this? – Meir Zeilig-Hess Jan 07 '16 at 21:14
1

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.

bibi
  • 3,671
  • 5
  • 34
  • 50