update 2003/ 2/11
![]() | |
![]() |
![]() ![]() ![]() ![]() |
![]() |
It's working !
(Anakin, Tatooine)
One nice point to use gnuplot in your scientific activity is that we can reuse the plot-file. We often draw very similar figures those have same axis names, same ranges, etc. but the numeric data inside the graph are different. With gnuplot you can do this by using only one plot-file. To do it, change the data file name at plot "datafile" or use the same data file name by the file is overridden by various data. Gnuplot batch mode is very useful when you want to make a large number of figures at one time. If your are doing this with something else, you have to struggle with your computer until midnight. Why don't you make your life easier with gnuplot and some UNIX commands to generate many figures within a few seconds. We think about a case that you have many data files --- calc1.dat, calc2.dat, calc3.dat --- in your directory, and each of the files contains simple (X,Y) data. Firstly, we make a graph of the data file, calc1.dat . Here we define the figure title, name of axes, X and Y ranges, and graduations, just like we did in the numerical calculation section.
A PNG image file is generated by gnuplot, when you "feed" this data.plt file to gnuplot. If you need an EPS file, use set terminal postscript , and change the name of output file properly, like calc1.eps.
![]() Now we reuse this to make a figure of another data file. To do it, we have to rewrite the file names "calc1.dat" and "calc1.png" in that file. Unfortunately you cannot use strings-type data in a gnuplot command, we replace the text "calc1" into "calc2" with the UNIX command, sed. Alternatively, those file names are give as command line options of a shell script. The following command changes the text "calc1" in a file into "calc2".
This one-line command makes a new figure, calc2.png. You repeat this for all your data files. When the number of data is not so large, you can use a shell-loop ('foreach' of csh, or 'for' of sh). csh, tcsh
sh, bash
When you have many files, you can remove the extension '.dat' of the file name with sed like below. Be careful that there are quotation and back-quotation marks. The inside sed command is to remove '.dat' extention if the variable $i , and the outside is to convert the strings "calc1."
You can also make a shell script to draw figures one-by-one. Once you make such a script, you can reuse this for other jobs. The script contains many lines corresponding to the number of your data files.
To make this you can use the UNIX commands, 'ls' and 'awk'. The following one-line command shows you the list of commands with which you can make many figures at one time. To make a shell-script file, re-direct this output to a file ( command > script.sh ).
You can write gnuplot commands directly in a shell script, and your file name is given as a command line option. To do this, use a "here document" of the UNIX shells. In this example, we make an EPS file "calc1.eps" from the data file "calc1.dat."
As you can see in the above example, the names of data and EPS files (without extensions) are replaced by a variable $1. The real names of those variables are given as the command line option to this shell script plot.sh. This script makes the EPS file "calc1.eps" from the data file "calc1.dat" when the command is invoked like below. With this method you can make a figure of your data files which are in a different directory, and the result is stored in the same directory.
To change the names of data file and EPS, you replace one of the $1 variables in the script above into $2, and give two command line options to this script. Finally the next shell script makes it possible to generate many figures within a second.
from Dr. Sato. Thanks !
![]() |
![]() | |
![]() |
![]() ![]() ![]() ![]() |
![]() |