Mike Pegg
Mike Pegg

Reputation: 11

Creating an animation from multiple data files

I have some C++ code that generates data I want to create an animated gif (or equivalent) from. The data is output into .txt files with the names 1, 2, 3, 4 ..., N with 2 columns (x y data points). For simplicity say we use 100 files.

There seems to be 1 of 2 ways to do this, either create 100 png images from the 100 files then use GIMP to create a gif or create a gif automatically via GNUplot. The first I should be able to do with a loop, say;

set term png for [i=1:100] {set output "data".i."png"; plot 'filepath/'.i.'.txt' with lines title ""; set output}

Which gives me the error: 'invalid complex constant'. This I suspect is just be being bad with GNUplot syntax.

As for the second, the examples I can find make it unclear how to use data to generate the plots.

Any help is much appreciated.

Upvotes: 1

Views: 1441

Answers (1)

Christoph
Christoph

Reputation: 48430

For gnuplot versions older than 4.6 you can use reread to do such kind of looping.

Consider the file looper.gp:

set output 'data'.i.'.png'
plot 'filepath/'.i.'.txt' with lines notitle
i = i + 1
if (i <= 100) reread

Call this with

i = 1
set terminal png
load 'looper.gp'
set output

Upvotes: 1

Related Questions