Select all files in a directory at the same time as gnuplot?

I want to do something similar to this question: gnuplot: displaying data from several input files in one graph .

I want to create all the files in a directory at the same time, without explicitly specifying their names. Column numbers are the same for all files. What can I do?

Doing plot for [file in *] file u 3:2 does not work.

In addition, I do not want each file to have a different legend. All points from all files should be processed the same way, as if they were all from the same file.

+7
gnuplot
Apr 30 '15 at 13:43 on
source share
4 answers

You can try something like:

 a=system('a=`tempfile`;cat *.dat > $a;echo "$a"') plot au 3:2 

This uses the tempfile command-line command to create a safe, unique, and one-time temporary file. It dumps all data files to this file. He then repeats the file name so that gnuplot can recover it. Then Gnuplot is plotting things.

Concerned with the headlines? Try the following:

 a=system('a=`tempfile`;cat *.dat | grep "^\s*[0-9]" > $a;echo "$a"') 

The regular expression ^\s*[0-9] will match all lines starting with any number of spaces followed by a number.

+5
Apr 30 '15 at 17:45
source share

As an alternative to Jonathan's answer, I would go with

 FILES = system("ls -1 *.dat") plot for [data in FILES] data u 1:2 wp pt 1 lt rgb 'black' notitle 

or

 plot '<(cat *.dat)' u 3:2 title 'your data' 

The first option gives you more flexibility if you want to mark each curve. For example, if you have several files with the names data_1.dat , data_2.dat , etc., Which will be marked as 1 , 2 , etc., Then:

 FILES = system("ls -1 data_*.dat") LABEL = system("ls -1 data_*.dat | sed -e 's/data_//' -e 's/.dat//'") plot for [i=1:words(FILES)] word(FILES,i) u 3:2 title word(LABEL,i) noenhanced 
+6
Aug 14 '15 at 16:07
source share

I like being able to select files to print using wildcards, so if you like it, you can do the following, although there are many ways. Create the following script.

script.sh:

 gnuplot -p << eof set term wxt size 1200,900 title 'plots' set logs set xlabel 'energy' plot for [ file in "$@" ] file wl eof 

do chmod u+x script.sh

Run as ./script.sh dir/* *.dat

If you need it, often make an alias for it and put it in some reasonable place :) Cheers / J

+2
May 01 '15 at 17:04
source share

Try the following command:

 gnuplot -e 'plot for [file in system("find . -depth 1 -type f -print")] file u 3:2' 

Note. Add -p to save the chart window.

0
Feb 13 '18 at 14:17
source share



All Articles