gnuplot / datafile (2)
not so FAQ
|
データファイルの数値のプロット (その2)一つのファイルに入った複数のデータをプロットするには? 一つのファイルに複数のデータを書いてそれらを同時にプロットするには, X座標が同じでY座標が異なるデータをプロットするときは,データを表形 # 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 ![]() X座標が異なる場合は,複数のデータを2行の空行で区切ってブロックにす # 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 ![]() ここの例で分かるように,データをブロックにしてプロットした場合, 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 ![]() indexは範囲を指定することもできます.上の例で,index 0とindex 1に gnuplot> plot "test.dat" index 0:1 using 1:2:3 with yerrorbars, "test.dat" index 2 using 1:2:3 with yerrorbars ![]() ファイルの数値をプロットする時に,数値を修正したい. usingの後に指定するカラムに簡単な演算ができます.プロットする # 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 $nで,nカラムのデータを指定し,それに演算を施します.このとき計算 この方法は誤差付きデータを表示するときに便利なことがあります. データファイルにプロットのコマンドも一緒に入れたい.gnuplotではプロットするデータのファイルと,実行するコマンドを記述し 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 このようなデータ込みのgnuplot制御用ファイルを用意し,gnuplot % gnuplot "test.plt" 但し,この方法ではreplotコマンドは使えません.gnuplotはデータを記 特定のデータをスキップしてプロットしたい. ファイル中の幾つかのデータを消してしまいたい場合があります.plot時 下の2つの例の様に,(X,Y1)と(X,Y2)のグラフを描く場合を考えます.
左の例ではX座標に?が付いていおり,2番目のデータである(2.0,1.8)と 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 ![]() この機能は,データが表形式になっているときに,各カラムでの表示範囲 # 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 Y1はXが[1:3]の範囲で0なので対数にはなりません.gnuplotはこの場合, ![]() この鉛直線を消すには,Y1=0.0の部分にプロット出来ない文字を書き込み ![]() ファイルの一部だけをプロットしたい. データファイル中で,プロットするデータの範囲(データファイル中の行)を データファイルが1行の空行で区切られた幾つかのデータブロックに分かれている
データファイルの最初や最後の数行だけを切り出して 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 1行目のplot例ではデータファイル “test.dat”の最初の10行だ from an Iwata-kun’s question. Thanks !
|