Generating graphs for many number of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generating graphs for many number of files
# 1  
Old 02-10-2013
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 :

Code:
gnuplot> load 'plot'

and this 'plot' file contains the following lines.

Code:
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 :

Code:
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.
# 2  
Old 02-11-2013
Not sure what your data files are like, but how about this:

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

do for[i=950:960] {
    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
}

# 3  
Old 03-01-2013
no

HTML Code:
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.
# 4  
Old 03-03-2013
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:

Code:
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

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 03-03-2013
Quote:
Originally Posted by Chubler_XL
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
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

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

And the above line 1 is :

Code:
for file in *_data

Is it due to the version problem of gnuplot or wrong with the way i am using it ?
# 6  
Old 03-03-2013
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:

Code:
$ 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

$


Last edited by Chubler_XL; 03-03-2013 at 07:38 PM..
This User Gave Thanks to Chubler_XL For This Post:
# 7  
Old 03-03-2013
thanks

@ 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generating a POSIX random number?

Hi Guys and gals... As you know I am getting to grips with POSIX and hit this stumbling block. Generating two random numbers 0 to 255 POSIXly. Speed in not important hence the 'sleep 1' command. I have done a demo that works, but it sure is ugly! Is there a better way? #!/bin/sh # Random... (12 Replies)
Discussion started by: wisecracker
12 Replies

2. Shell Programming and Scripting

Random number generating script?

Having a hard time with this. Very new to scripting and linux. Spent all sunday trying to do this. Appreciate some help and maybe help breaking down what the syntax does. Create a Bash program. It should have the following properties • Creates a secret number between 1 and 100 i. The... (3 Replies)
Discussion started by: LINUXnoob15
3 Replies

3. Shell Programming and Scripting

Generating Random Number in certain range

Hi there I am trying to generate a random number between 40 and 70 using the shell here is my code so far and it keeps going above 70. all help much appreciated! comp=$(( RANDOM%70+40 )) echo $comp (4 Replies)
Discussion started by: faintingquiche
4 Replies

4. Shell Programming and Scripting

Help with ahem Prime number Generating Script

Can anybody tell me why the second part of this script (Sieve of Eratosthenes) isn't working properly. This isnt coursework or homework just private studies ( Yes Project Euler began it ) I know there are easier ways of doing this too but I want to do it this way.:p Iam using Cygwin on Vista... (3 Replies)
Discussion started by: drewann
3 Replies

5. Programming

Generating Random Number in Child Process using Fork

Hello All, I am stuck up in a program where the rand functions ends up giving all the same integers. Tried sleep, but the numbers turned out to be same... Can anyone help me out how to fix this issue ? I have called the srand once in the program, but I feel like when I call fork the child process... (5 Replies)
Discussion started by: manisum
5 Replies

6. Programming

C Help; generating a random number.

Im new to C, and Im having a hard time getting a random number. In bash, I would do something similar to the following to get a random number; #!/bin/bash seed1=$RANDOM seed2=$RANDOM seed3=$RANDOM SEED=`expr $seed1 * $seed2 / $seed3` echo ${SEED%.*} Now, in online examples... (4 Replies)
Discussion started by: trey85stang
4 Replies

7. Programming

generating 16 digit random number in C

Hi, How can we generate 16 digit random nos in C. (10 Replies)
Discussion started by: ajaysahoo
10 Replies

8. Shell Programming and Scripting

Generating random number within a specific range (0.5-1.5)

Hello, need a way to generate numbers within 0.5-1.5 range Has to be totally random: 0.6 1.1 0.8 1.5 0.6 and so on.... How to? (10 Replies)
Discussion started by: TehOne
10 Replies

9. Shell Programming and Scripting

Generating files.

I/P file name:- 20092008.txt Check number of entries in i/p file by following command ChkEnt -infl 20092008.txt -opfl 20092008_test.txt >count.txt Dear Friends, Please help me in automating following thing. If output generated (count.txt) is having value more than 1000 i.e.... (8 Replies)
Discussion started by: anushree.a
8 Replies

10. UNIX for Dummies Questions & Answers

Generating line number

Hi, I am generating a file through some Datastage commands: cat $TempDir/stage.txt |while read line do stagename=`echo $line` dsjob -llinks $proj $jobname $stagename 2>/dev/null >> $TempDir/LinkName.txt Now i have to assign the number... (5 Replies)
Discussion started by: Amey Joshi
5 Replies
Login or Register to Ask a Question