supriyo
supriyo

Reputation: 21

how to plot different datafiles, saved in certain format, into a single plot using gnuplot script

I have file named 1000_0.dat, 2000_0.dat,... and similarly 1000_1.dat, 2000_1.dat,... how to plot all the files into a single plot using gnuplot script? Thanks for your help!

Upvotes: 1

Views: 75

Answers (1)

andyras
andyras

Reputation: 15910

The syntax is

plot 'data1.dat', 'data2.dat' ...

Just separate the data files with commas. You can also put each file name on a different line if you want it to be easier to read,

plot 'data1.dat', \
     'data2.dat'

If you want to totally automate it, you can use the for syntax in the newer (4.6+) versions of gnuplot:

plot for [i=0:1] for [j=1e3:2e3:1e3] ''.j.'_'.i.'.dat' title ''.j.'_'.i.'.dat'

This is a doubly nested loop which will plot all the files and label them appropriately. . is the string concatenation operator in gnuplot. I set the title manually because otherwise it displays ''.j.'_'.i.'.dat' for all the plots. The leading '' before the file name and title is because gnuplot won't recognize that it should print the index i or j as a string unless it comes after another string, in this case an empty one.

Upvotes: 1

Related Questions