Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Plotting from many data files by means of a for loop

7,694 views
Skip to first unread message

Henning Haida

unread,
Dec 14, 2009, 4:36:21 AM12/14/09
to
Dear all,

I have many datafiles, named file1.dat, file2.dat, file3.dat and so on
up to a large number (about 1000, e.g. data1000.dat). How Do I plot them
into a single plot? I dream of something like

...
for i=1:1000
plot "data<i>.dat" using 3:4 with lines
end
...

Is this possible by means of gnuplot? Any help is appreciated!


Regards
Henning

Juergen Wieferink

unread,
Dec 14, 2009, 5:17:11 AM12/14/09
to

In recent versions of gnuplot (e.g. 4.4) there is the possibility of
iterations. Have a look at "help plot iteration" and "help
sprintf". Something like

plot for [i=1:1000] sprintf('data%i.dat', i) using 3:4 with lines


might be what you are searching for.


Juergen

Henning Haida

unread,
Dec 14, 2009, 9:31:31 AM12/14/09
to
Am 12/14/2009 11:17 AM, schrieb Juergen Wieferink:
> In recent versions of gnuplot (e.g. 4.4) there is the possibility of
> iterations. Have a look at "help plot iteration" and "help
> sprintf". Something like
>
> plot for [i=1:1000] sprintf('data%i.dat', i) using 3:4 with lines

Thanks a lot! This works fine for me!

Regards,
Henning

Péter Juhász

unread,
Dec 15, 2009, 7:36:32 AM12/15/09
to
On Dec 14, 3:31 pm, Henning Haida <losmin...@midnightallstars.de>
wrote:

Even more versatile is the following syntax:

list = "`echo $(ls data*.dat file*.dat)`"
plot for [i in list] i using 1:2 w l tit i

This allows you to use more than one file specifications to gather
file names in the variable 'list', then iterate over that list and
plot the files one by one.

Péter Juhász

Juergen Wieferink

unread,
Dec 15, 2009, 7:42:18 AM12/15/09
to
Péter Juhász wrote:
> Even more versatile is the following syntax:
>
> list = "`echo $(ls data*.dat file*.dat)`"
> plot for [i in list] i using 1:2 w l tit i
>
> This allows you to use more than one file specifications to gather
> file names in the variable 'list', then iterate over that list and
> plot the files one by one.

True. But as backticks are depricated (or IMHO should be, at least
within strings), you can use

list = system("echo $(ls data*.dat file*.dat)")

instead.

Juergen

0 new messages