Generating graphs for many number of files

Hi,

I have a series of data files [ each file contains three columns ] for which I wish to plot using "splot". Say, the files names are like:

950_data,951_data,952_data,......1000_data.

For one file , say to plot 950_data, i write following lines into a single file and load it in the gnuplot as :

gnuplot> load 'plot' 

and this 'plot' file contains the following lines.

splot '950_data' with lines
set xlabel "year"
set ylable "population"
set zlabel "country"
set title "950_survey"
set terminal png
set output '950.png'
replot

If you can see that the above is only for file named " 950_data" . I want to do this for all files from 950_data to 1000_data.
It is to be noted that the :

set title "950_survey"
set output '950.png'

has to be updated properly from 950 to 1000 files we have.

Can anyone help this with the use of the loop in the gnuplot.

Thanks.

Not sure what your data files are like, but how about this:

set xlabel "year"
set ylabel "population"
set zlabel "country"
set terminal png

do for {
    set output sprintf("%d.png",i)
    set title sprintf("%d_survey",i)
    splot sprintf("%d_data",i) title sprintf("%d_data", i) with lines
    replot
}
Chubler_XL;302773837]How did you go with the solution I posted for you in this thread?

That is not the solution. The using loop inside gnuplot seems to be different than using it normally.

I have tried with it as it is ., it did not worked.
Done with some changes, again no use of it.

Using a loop within gnuplot is the most efficient, but if it's proving to be too hard for you to maintain you could try using a bash/ksh loop and call gnuplot once for each file like this:

for file in *_data
do
   V=${file%_data}
   gnuplot <<EOF
set xlabel "year"
set ylabel "population"
set zlabel "country"
set title "${V}_survey"
set terminal png
set output "${V}.png"
splot "${V}_data" with lines
EOF
done
1 Like

Hi Chubler_XL,

I tried with the code like calling gnuplot separately for each file .., but it did not worked.

Is it because the in Gnuplot Version 4.4, the loop features is not introduced ? Because, whenever i load the file containing the code which has " for loop" in it, is not at all executing. A message is displayed like

for file in *_data
^
"test", line 1: invalid command

And the above line 1 is :

for file in *_data

Is it due to the version problem of gnuplot or wrong with the way i am using it ?

The posted solution was a shell script that calls gnuplot for each data file.

Save the code to a file as plotdata.sh in same directory as your _data files and from unix command line use:

$ ls
950_data  952_data  954_data  956_data  958_data  960_data
951_data  953_data  955_data  957_data  959_data  plotdata.sh

$ chmod 755 plotdata.sh 

$ ./plotdata.sh 

$ ls
950.png   952.png   954.png   956.png   958.png   960.png
950_data  952_data  954_data  956_data  958_data  960_data
951.png   953.png   955.png   957.png   959.png   plotdata.sh
951_data  953_data  955_data  957_data  959_data

$
1 Like

@ Chubler_XL : I was about to write my comment as it was my mistake in the way i was running the script. But , you have pointed out exactly what mistake i done. Thanks a lot, for your kind cooperation.