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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

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?
What is the difference between tab, flt and dbl files? Those aren't standard file extensions.
@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.
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.
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.
|
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.