-1

I have a lot of results which i want to plot and save them automatically. I had tried to find in the help manual but not yet. It take me a lot of time when i plot each of file. Could you please help me?

E.g., i have 10 text files with their name are conf-a00 to conf-a09, i want to plot and save them automatically.

Many thanks for your helps.

Vinh-Du

vinh-du
  • 11
  • 2

1 Answers1

1

You have several possibilities:

  • you can use a "template".

For instance if you have the following file foo.gpl:

#foo.gl
set term png
set output "OUTFILE"
plot "DATAFILE" using 1:2 with lines

you can then use a shell script to modify your template:

#!/bin/bash
for i in {01..09}
do
    sed 's/DATAFILE/conf-a'${i} s/OUTFILE/graph'${i}'.png/' template.gnuplot > /tmp/foo
    gnuplot /tmp/foo
done
rm /tmp/foo
  • use variables in gnuplot

with something like (not tested):

in gnuplot, you do

i = 1
n = 9
set term png
load "loop.gpl"

with loop.gpl containing:

datafile = "conf-a0".i
outfile  = "graph".i.".jpg"

set output outfile
plot datafile using 1:2 with lines
set output
i=i+1
if (i <= n) reread

(you have a similar answer here)

  • in gnuplot > 4.6

you can use foor loop:

do for [t=0:9] {
    datafile = sprintf('conf-a0%f',t)
    outfile = sprintf('graph%f.png',t)
    set output outfile
    plot datafile using 1:2 with lines
}

Edit: using your info:

cat newloop.gpl:

datafile = "data-a0".i 
outfile = "graph0".i.".png" 
set output outfile 
plot datafile w lp lw 2.5 
i=i+1 
set output
if (i <= n) reread 

in gnuplot:

gnuplot> i = 1 
gnuplot> n = 5 
gnuplot> set grid
gnuplot> set logscale x 
gnuplot> set xlabel 'P (kPa)' 
gnuplot> set ylabel 'Z' 
gnuplot> set format y "%.2f" 
gnuplot> set format x "10^{%L}" 
gnuplot> set title 'Coordination number in isotropic pressure cycle' 
gnuplot> set pointsize 2
gnuplot> 
gnuplot> load "newloop.gpl"

That produces graphs of different sizes:

-rw-rw-r-- 1 fred fred   5430 avril 17 23:20 graph01.png
-rw-rw-r-- 1 fred fred   5228 avril 17 23:20 graph02.png
-rw-rw-r-- 1 fred fred   5248 avril 17 23:20 graph03.png
-rw-rw-r-- 1 fred fred   5685 avril 17 23:20 graph04.png
-rw-rw-r-- 1 fred fred   5818 avril 17 23:20 graph05.png
Community
  • 1
  • 1
fredtantini
  • 15,966
  • 8
  • 49
  • 55
  • Thank you so much fredtantini – vinh-du Apr 17 '14 at 11:18
  • i applied your ways but it only export the first result file, the others files is not exported although i had tried to use your three ways. It is the same situation. – vinh-du Apr 17 '14 at 13:39
  • This is the code is used set term pngcairo transparent enhanced font "Helvetica,22" fontscale 1.0 size 1420,1000 i = 1 n = 5 set grid set logscale x set xlabel 'P (kPa)' set ylabel 'Z' set format y "%.2f" set format x "10^{%L}" set title 'Coordination number in isotropic pressure cycle' set pointsize 2 datafile = "cnprv0".i outfile = "cnprv0".i.".png" set output outfile plot datafile w lp lw 2.5 i=i+1 if (i <= n) reread set output – vinh-du Apr 17 '14 at 15:22
  • @vinh-du I have edited my answer, but I think you made a mistake somewhere. It works fine with me. – fredtantini Apr 17 '14 at 21:25
  • do for [i = 0:5] { datafile = sprintf('phi45-f002-v0%d.txt',i) outfile = sprintf('phi45-f002-v0%d.png',i) set output outfile do for [j in "0.1 0.5 1.0 1.5 2.0"]{ plot datafile t '{/Symbol F}=0.45-f=0.02-v='.j with boxes,\ datafile using 1:($2+1.5):2 with labels notitle } } @fredtantini: i had edited this code and it's ok. I have another problem: i want to export the series of output files with the name of diagram is added the extention name "j". Could u pls help me! – vinh-du Apr 22 '14 at 14:32