UNIX上でグラフを描く方法を説明します。計算結果のグラフを画面に表示してみましょう。
より詳しい説明は、 gnuplot FAQ (FAQ = Frequently Asked Question, まあ、よくある質問ということですね。) を参照して下さい。
ap1: gnuplot
G N U P L O T
Unix version 3.7
patchlevel 0
last modified Thu Jan 14 19:34:53 BST 1999
Copyright(C) 1986 - 1993, 1998, 1999
Thomas Williams, Colin Kelley and many others
Type `help` to access the on-line reference manual
The gnuplot FAQ is available from
Send comments and requests for help to
Send bugs, suggestions and mods to
Terminal type set to 'x11'
gnuplot> plot sin(x)
とりあえず、ここでいったん gnuplot を終りましょう。
gnuplot> quit
まず、プロットする点の座標を順番に並べたファイルを用意します。一行ごとにx座標とy座標を書いておきます。例えば y=x*x のデータは
0.0 0.0 1.0 1.0 2.0 4.0 3.0 9.0
となります。二つの数値の間にスペースを忘れないでください。そして数値以外の文字列は書いちゃだめです。
こんなデータを手で入れていたら大変ですが、 例えば a.out の出力をファイルにすれば (ファイルに出力) 簡単に作れますね。
といった感じです。
それでは、グラフを描くgnuplotというコマンドを入力して、 さっきのデータファイルをプロットしてみましょう。
ap1: gnuplot
G N U P L O T
Unix version 3.7
patchlevel 0
last modified Thu Jan 14 19:34:53 BST 1999
Copyright(C) 1986 - 1993, 1998, 1999
Thomas Williams, Colin Kelley and many others
Type `help` to access the on-line reference manual
The gnuplot FAQ is available from
Send comments and requests for help to
Send bugs, suggestions and mods to
Terminal type set to 'x11'
gnuplot> plot "hoge.data"
画面にグラフが出ましたか?データファイル名の両端の " は忘れないでください。
次にプロットの仕方をいろいろ変えてみましょう。
gnuplot> plot "hoge.data" with lines gnuplot> plot "hoge.data" with linespoints
データファイルが2個ある場合、二つを同時にプロットするには
gnuplot> plot "hoge.data","hoyo.data"
とします。
0.0 0.0 0.0 1.0 1.0 1.0 2.0 4.0 8.0 3.0 9.0 27.0というデータファイル、hoge1.dat があった時に、x 軸に1カラム目、 y 軸に3カラム目をプロットさせたい時は、
gnuplot> plot "hoge1.data" using 1:3
終了するには
gnuplot> quit
まず、結果を Postscript で出力するために、
gnuplot> set terminal postscript
Terminal type set to 'postscript' Options are 'landscape monochrome dashed "Helvetica" 14'
gnuplot> set output "ファイル名"
gnuplot> plot "hoge.dat"
gnuplot> quit ap1: ls hoge.ps temp work www
ap1: ghostview hoge.ps ap1: display hoge.ps
(* 注: 現在、プリンターは(紙が無くて)使えません。)
プリンターが使えるのであれば、出力してみます。
そのためのコマンドは、
lpr -Ppsc600 ファイル名 です。
(注:このコマンドでプリントアウトするのは、Postscript ファイルのみ
にしてください。)
ap1: lpr -Ppsc600 hoge.ps
gnuplot> help plot