-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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much fredtantini
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.
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 I have edited my answer, but I think you made a mistake somewhere. It works fine with me.
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!

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.