gnuplot / datafile (2E)
not so FAQ |
Plotting Numerical Data in a Data File (No.2)How do I plot several data sets in a single file ? In order to plot several data those are stored in one file, use When those data have the same X-values, prepare the # X Y1 Y2 Y3 -1.0000 0.0000 0.0000 1.0000 -0.9000 0.5700 1.1769 0.7150 -0.8000 1.0800 1.4400 0.4600 -0.7000 1.5300 1.4997 0.2350 -0.6000 1.9200 1.4400 0.0400 -0.5000 2.2500 1.2990 -0.1250 -0.4000 2.5200 1.0998 -0.2600 -0.3000 2.7300 0.8585 -0.3650 -0.2000 2.8800 0.5879 -0.4400 -0.1000 2.9700 0.2985 -0.4850 0.0000 3.0000 -0.0000 -0.5000 0.1000 2.9700 -0.2985 -0.4850 0.2000 2.8800 -0.5879 -0.4400 0.3000 2.7300 -0.8585 -0.3650 0.4000 2.5200 -1.0998 -0.2600 0.5000 2.2500 -1.2990 -0.1250 0.6000 1.9200 -1.4400 0.0400 0.7000 1.5300 -1.4997 0.2350 0.8000 1.0800 -1.4400 0.4600 0.9000 0.5700 -1.1769 0.7150 1.0000 0.0000 -0.0000 1.0000 gnuplot> plot "test.dat" using 1:2 with lines, "test.dat" using 1:3 with lines, "test.dat" using 1:4 with lines ![]() When the X-values are different, the whole data are separated into # X Y Yerror 1.0 1.2 0.1 2.0 1.8 0.1 3.0 1.6 0.1 1.1 0.8 0.2 2.1 0.3 0.2 3.1 1.0 0.2 1.2 1.5 0.3 2.2 2.3 0.3 3.2 3.1 0.3 gnuplot> plot "test.dat" using 1:2 with lines ![]() gnuplot> plot "test.dat" using 1:2:3 with yerrorbars ![]() As you can see above, all the data in the different data blocks gnuplot> plot "test.dat" index 0 using 1:2:3 with yerrorbars, "test.dat" index 1 using 1:2:3 with yerrorbars, "test.dat" index 2 using 1:2:3 with yerrorbars ![]() You can specify the range of index. For example, to use the same gnuplot> plot "test.dat" index 0:1 using 1:2:3 with yerrorbars, "test.dat" index 2 using 1:2:3 with yerrorbars ![]() I want to modify values in my data file when plotting. You can make some simple calculations and change the data of the # X Y 1.0 1.2 2.0 1.8 3.0 1.6 gnuplot> plot "test.dat" using 1:2 with points, "test.dat" using 1:($2*2) with points, "test.dat" using 1:(sqrt($2)) with points, "test.dat" using 1:(log($2)) with points Specify the n-th column by $n , and make some Sometimes this technique is useful when you have a data file I want to put some plotting commands in a data file. Gnuplot uses two files, one is the data and another is the control set xrange [0:5] set yrange [0:3] plot "-" using 1:2:3 w yerrorbars # X Y Z 1.0 1.2 0.2 2.0 1.8 0.3 3.0 1.6 0.2 4.0 1.2 0.2 end pause -1 Prepare a control file which includes the data just like above, % gnuplot "test.plt" By the way, you cannot use the replot command in this I want to eliminate some data points. There are two ways to skip some data in a data file — the first The next example is to draw graphs of (X,Y1) and (X,Y2).
In the left drawing, the second X value has “?” mark, so that gnuplot> plot "test1.dat" using 1:2 with linespoints, "test1.dat" using 1:3 with linespoints ![]() gnuplot> plot "test2.dat" using 1:2 with linespoints, "test2.dat" using 1:3 with linespoints ![]() This function is useful if you want to alter the range # X Y1 Y2 1.0 0.0 0.1 2.0 0.0 0.1 3.0 0.0 0.1 4.0 0.1 0.2 5.0 0.6 0.4 6.0 1.0 0.9 7.0 1.2 1.7 8.0 1.3 2.4 The Y1-values are zero in the X range of [1:3], so you cannot ![]() To remove this vertical line, put “?” at Y1=0.0, like “?0.0”. ![]() How do I plot a part of data in a file ? To specify a range of the data to be plotted, use the every . When the data file contains several data blocks those are separated .
Alternatively (if you are on the UNIX-like system), gnuplot> plot "< head -10 test.dat" using 1:2 with lines gnuplot> plot "< tail -3 test.dat" using 1:2 with lines gnuplot> plot "< head -5 test.dat" using 1:2 with lines, > plot "< tail -5 test.dat" using 1:2 with points The first “plot” command says to plot the first 10 lines in the from an Iwata-kun’s question. Thanks !
|