gnuplot
gnuplot
gnuplotを用いて簡単なグラフの描画をする方法を紹介します. gnuplotは本来は対話的に使用することができますが,プロラボの環境の関係で, linuxマシン上でデータファイルを作り,それをsftpしてこちら側 でgnuplotさせるという方法をとります.
gnuplotの詳しい使用法は,河野@LANLさんのサイト にあります.
sftp
sshの上でファイルをやりとりするプロトコルftp(file transfer protocol)を動かします.WindowsXPのスタートメニュからcygwinを立ち上げて,以下のようにします
$sftp bob@210.81.220.86 Connecting to 210.81.220.86... sftp> get NumRecipeEx07/test.eps Fetching /Users/bob/NumRecipeEx07/test.eps to test.eps /Users/bob/NumRecipeEx07/test.eps 100% 4442KB 2.2MB/s 00:02
初めに
sftp bob% 192.218.172.86
として接続し,そこで
get NumRecipeEx07/test.eps
でファイルをゲットしています.
もっとも単純な例
サイコロを二つ投げて和を記録した結果が次のようであったとします.
#100 2 1 3 5 4 12 5 8 6 16 7 13 8 8 9 12 10 13 11 11 12 1
これをsftpで持ってきて"dice100.res"とします.Cygwin上でgnuplotを立ち上げて,
gnuplot> set terminal png gnuplot> set output "test.png" gnuplot> plot "dice100.res" with line
としてください.test.pngをwindows上でダブルクリックするとFIREWORKSが立ち上がって以下のような絵が 表示されるはずです.

課題1
上記のグラフを作成せよ.ただし,サイコロの試行は1000回とせよ.
課題2
コインの表が出た枚数をプロットせよ.試行回数が多くなるにつれて半値幅(一山型のピークから値が半分になる幅)が小さくなることを確かめよ.
課題3
以下のようにサイコロの試行回数を変えた場合(100,1000,10000回)のデータを1つのファイルに入れて,一度にプロットせよ.
#100 2 2 3 9 . . . 11 4 12 0 #1000 2 28 3 49 4 81 . . .
データのブロックの間は2行以上あける必要がある.以下のコマンドで描画できるはず.その解説は実験データ編にある.
gnuplot> plot "dice.res.all" index 0 w l, "dice.res.all" index 1 w l
"w l"は"with line"の略.
課題4(時間が余った人用)
3次元関数の表示は以下の通り.これはMandelbrot集合と呼ばれる図.プログラムを書くために必要な解説はこちら.
gnuplot> set pm3d map gnuplot> set size ratio -1 gnuplot> splot "f1.dat"

Keyword(s):
References:[LinuxEx]