gnuplot / datafile (3E)
not so FAQ |
Plotting Numerical Data in a Data File (No.3)How do I use UNIX commands inside gnuplot. With gnuplot you can modify the data Here we use the following commands. sort With the sort command, you can concatenate / merge several
% sort -n file1.dat file2.dat 1.0 0.1 2.0 0.2 4.0 0.6 5.0 0.5 5.0 1.0 8.0 0.8 10.0 1.2 12.0 1.3 Two datasets are shown by symbols, then all data points are gnuplot> plot "< cat -n file1.dat file2.dat" using 1:2 w l, > "file1.dat" u 1:2 w p, > "file2.dat" u 1:2 w p ![]() pastePaste command puts more than two files side by side.
% paste file1.dat file2.dat 1.0 0.1 1.0 0.6 2.0 0.2 2.0 1.0 3.0 0.5 3.0 1.2 4.0 0.8 4.0 1.3 To draw figure of (X,Y) pairs when X data are in ‘file1.dat’ and Y gnuplot> plot "< paste file1.dat file2.dat" using 2:4 w lp You can compare two files with this command. The paste gnuplot> plot "< paste file1.dat file2.dat" using 1:($2/$4) w points from Ken. Thanks !
sed The stream editor sed is very powerful tool to edit your Shift X data of 1.0 to 1.2. gnuplot> plot '<sed "s/^ 1.0/ 1.2/g" file1.dat' Show all data points, but draw a line which does not pass through gnuplot> plot 'file1.dat' u 1:2 with points, > '<sed "/^ 2.0/d" file1.dat' u 1:2 with lines ![]() Remove the third line. gnuplot> plot '<sed "3d" file1.dat' u 1:2 with points awk Awk is also very powerful language with which you can Cumulative values of Y data are plotted with a bar graph. The last gnuplot> plot "<awk '{x=x+$2; print $1,x}' file1.dat" with boxes ![]() Change Y into zero when Y is less than 0.2. gnuplot> plot "<awk '{print $1,($2<0.1) ? 0.0 : $2}' file1.dat" with lines Multiply Y-values by 5 when X is in the range of [1:3]. gnuplot> plot "<awk '{print $1,($1<=3 && $1>=1) ? $2*5 : $2}' file1.dat" with lines |