gnuplot使い方
サンプルデータ|
簡単なチュートリアル|
Quiz|
GNUPLOT
Links|
ホームへ戻る|
サンプルデータ
-
energy.dat
まず、これをダウンロード/セーブして下さい。
-
演習17で 'MDOUT'を読み込んで運動エネルギーのヒストグラムを求めるプログラムを作りましたが、この
'energy.dat'はその実行結果から得られたものです。 ( a.out > energy.dat )
-
MDのプログラムでは、プリント文に文字 ('phase','energy')が入っていますが、gnuplotでプロットするときには入れないで下さい。
gnuplotの簡単なtutorial
~% gnuplot
energy.dat の1列目をx軸、2列目をy軸としてプロットするには、
gnuplot> plot "energy.dat"
線で結んだグラフを書くには、
gnuplot> plot "energy.dat" with line
関数を書くこともできる。
gnuplot> plot sin(x)
データと関数を重ねて書くこともできる。
gnuplot> plot "energy.dat" with line, sin(x)
原点付近に注目してみる。
gnuplot> plot [0:0.2][0:0.2] "energy.dat" with line, sin(x)
表示した絵をpostscriptファイル 'histgram.ps'に出力するには、
gnuplot> set output "histgram.ps"
gnuplot> set terminal postscript
gnuplot> replot
postscript ファイル 'histgram.ps'の内容を確認するには
~% ghostview histgram.ps
印刷するには、(注) 印刷はレポートに添付するものに限定してください。
紙の無駄使いは極力避けてください。
~% lp histgram.ps
ファイル 'test.inp' (どんな名前でもOK) のなかに実行したいコマンドの内容書いておけば、
下のようにタイプするだけでよい。
gnuplot> load "test.inp"
あるいは、シェルから直接、
~% gnuplot < test.inp
としてもOK。
Quiz
問 : このエネルギーはどのような分布にしたがっているか?
解 : maxwell分布である。
-
gnuplotで以下のコマンドを確かめてみよ。
-
-
まず、このヒストグラム(エネルギーの分布関数)がどのような形かを確かめる。
ヒストグラムを描くときは、styleを指定する。boxes か hist がいいだろう。
gnuplot> plot "energy.dat" with boxes
gnuplot> plot "energy.dat" with hist
最初に、正規分布でフィットしてみる。(実はうまくいかないことがあとで分かる)
そのために、正規分布の関数を定義する。
gnuplot> invsqrt2pi = 1.0 / sqrt(2.0 * pi )
gnuplot> normal(x) = invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2)
正規分布をプロットする。 muとsigmaの値は、さきほどのプロットからおおよそのmuとsigmaの値を代入する。
gnuplot> mu = 0.9
gnuplot> sigma = 0.5
gnuplot> plot [0:3] normal(x), "energy.dat"
正規分布でフィットしてパラメーター mu と sigma の値を決めてみる。
gnuplot> fit normal(x) 'energy.dat' via sigma, mu
gnuplot> replot
どうやら、正規分布ではないらしい。
そこで、maxwell分布でfitしてみる。まず、maxwell分布の関数定義。
gnuplot> fourinvsqrtpi = 4.0/sqrt(pi)
gnuplot> maxwell(x)=fourinvsqrtpi*a**3*x*x*exp(-a*a*x*x)
a=1 としてプロットしてみる。--> 正規分布よりも良いのでは?
gnuplot> a = 1
gnuplot> plot [0:3] maxwell(x), "energy.dat"
パラメーターaをfittingにより決めよう
gnuplot> fit maxwell(x), 'energy.dat' via a
gnuplot> replot
パラメーターaの値を表示
gnuplot> print a
最後に、データと二つの関数を全て表示
gnuplot> plot [0:3] maxwell(x), normal(x), "energy.dat"
-
このように、たくさんのコマンドを入力する場合は、Tutorialの項でも説明 したように、inp
fileを作ることがのぞましい。
Links
GNUPLOT 3.5 マニュアル(日本語訳)
GNUPLOTのリンク集
詳しい使い方は
gnuplot> help
と入力しても得られる。但し全て英語。