Register to reply

Simple loop script in Gnu Plot

by Don Carnage
Tags: gnu plot, loop, script, simple
Share this thread:
Don Carnage
Jan18-08, 06:25 PM
P: n/a
Ok, I have "n" data files containing coordinates on the form of (x,y) called:


What I want is to program a simple script in gnu plot(Linux) which load them and convert
them into *.gif files called:


I have already written a script that can convert ONE data file into ONE gif file, it looks like this:

$ nano plot
set terminal gif
set output 'koor.gif '
plot 'koor.dat' with lines
It loads the file called koor.dat and convert it into koor.gif - simple :P

SO; How do I make this script loop ?

Phys.Org News Partner Science news on
Fungus deadly to AIDS patients found to grow on trees
Canola genome sequence reveals evolutionary 'love triangle'
Scientists uncover clues to role of magnetism in iron-based superconductors
Jan18-08, 06:40 PM
P: 15,153
Gnuplot can't do what you want. You have to do the looping by hand (the hard way) OR use a scripting language that has the requisite capabilities (the easy way). Write a perl script (or Python script, or whatever) that generates the gnuplot script, and then invoke that gnuplot script.
Don Carnage
Jan18-08, 06:54 PM
P: n/a
hmm so what you suggest is that I write a script that generates a plot script looking like:

set terminal gif
set output '1.gif '
plot '1.dat' with lines,

then initiating 'gnuplot plot'.
Thereafter my python script shall rewrite the the plot script into:

set terminal gif
set output '2.gif '
plot '2.dat' with lines

and so on..!?

Don Carnage
Jan18-08, 06:59 PM
P: n/a
Simple loop script in Gnu Plot

I guess this is a quite slow process..
Are there libraries in C which are capable of plotting and converting into *.gif
I only know a bit of C programming but it should be sufficient..
Mar5-09, 01:25 PM
P: 89
please can anyone help me to plot with colors in G N U P L O T
Version 4.0 patchlevel 0, as I found some commands somewhere online, but it does not work, can you plaes show me how to do it, and how to add legends.....
Mar23-10, 01:14 AM
P: 2
So, this is horribly outdated, but if someone else stumbles by here with the same's the answer. You can do this, using a combination of an external script and the reread command.
You should be able to do something similar to the following...

load ""
#end of

set output sprintf("file.%d.gif",iter)
splot sprintf("file.%d.dat",iter) w lines
if(iter<=n) reread
#end of
Aug15-10, 04:08 PM
P: 186
It is possible to use:

plot for [i=1:10] ...

see the documentation!
Aug15-10, 07:22 PM
P: 2
mersecske's solution will work (much more elegantly than my previous solution)...

The only caveat is that it requires at least gnuplot version 4.3. If you try mersecske's solution and it doesn't work, check your version.

Register to reply

Related Discussions
Difference between Identical , Equal , Equivalent Calculus & Beyond Homework 9
QMD running G and Lambda challenges Loop Gravity Beyond the Standard Model 0
Cryotiger closed-loop CCD chiller repairs/service General Physics 0