I have several data files named sequentially as '1.dat', '2.dat' ..., '100.dat'. I want to create a png(or any other type) image for each of these data file in Gnuplot. My ultimate motif is to create a movie from the images thus generated but I found packages available for that confusing and would prefer to do it step by step. How can I write script for creating images out of the data files? Thanks.
1 Answer
If you have gnuplot 4.6, this becomes pretty easy:
do for [i=1:100] {
str_num=sprintf('%d',i) #Write integer to string
str_num2=sprintf('%03d',i) #integer as a 0 padded string
set term png
set output 'my_output.'.str_num2.'.png'
plot str_num.'.txt' ...
}
Note that you I have two versions of the number as a string: e.g. '1' for creating the name of the input datafile and '001' for the output datafile. This way, the output files will sort lexicographically which makes it easier for making a movie later.
If you don't have gnuplot 4.6, you'll need to use the old if/reread trick:
if (! exists('i')) i=1
#Contents of previous `for` loop here...
if (i<=100) reread
Initially, I thought you might be able to get away with plot iteration, but I don't think so. That would put all the data on 1 plot.