Simple loop script in Gnu Plot

  • Thread starter Thread starter Don Carnage
  • Start date Start date
  • Tags Tags
    Loop Plot
Click For Summary

Discussion Overview

The discussion revolves around creating a loop script in Gnuplot to automate the conversion of multiple data files into GIF images. Participants explore various methods to achieve this, including using external scripting languages and Gnuplot's own capabilities.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Peter seeks a way to loop through multiple data files in Gnuplot to generate corresponding GIF files.
  • One participant suggests that Gnuplot cannot handle the looping directly and recommends using an external scripting language like Perl or Python to generate the Gnuplot script.
  • Peter contemplates writing a script that generates individual Gnuplot scripts for each data file, but questions the efficiency of this approach.
  • Another participant inquires about C libraries that could handle plotting and GIF conversion.
  • A later reply mentions using a combination of an external script and the 'reread' command in Gnuplot to automate the process, providing a sample script structure.
  • Another participant points out that Gnuplot version 4.3 or higher is required for a specific solution involving a loop construct.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to automate the plotting process, with no consensus on a single method. Some advocate for external scripting, while others suggest using Gnuplot's built-in features.

Contextual Notes

There are limitations regarding the version of Gnuplot required for certain solutions, and the efficiency of the proposed methods remains uncertain.

Who May Find This Useful

This discussion may be useful for users of Gnuplot looking to automate the plotting of multiple datasets, particularly those familiar with scripting languages or seeking to understand Gnuplot's capabilities.

Don Carnage
Simple loop script in "Gnu Plot"

Ok, I have "n" data files containing coordinates on the form of (x,y) called:

1.dat
2.dat
3.dat
.
.
.
n.dat

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

1.gif
2.gif
.
.
.
n.gif

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

$ nano plot
Code:
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 ?

Peter
 
Last edited by a moderator:
Technology news on Phys.org
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.
 
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..!?
 
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..
 


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...
 


So, this is horribly outdated, but if someone else stumbles by here with the same question...here'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...

#file gnuscript.gp
iter=0
n=20
load "loadfile.gp"
#end of gnuscript.gp

#file loadfile.gp
iter=iter+1
set output sprintf("file.%d.gif",iter)
splot sprintf("file.%d.dat",iter) w lines
if(iter<=n) reread
#end of loadfile.gp
 


It is possible to use:

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

see the documentation!
 


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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 13 ·
Replies
13
Views
2K
Replies
1
Views
5K
Replies
19
Views
4K