#z=x*x+sin(y)のグラフを描いてみます。 # gnuplot> splot x*x+sin(y) #重ねてz=-x*x+y*yのグラフを描いてみます。 3 gnuplot> replot -x*x+y*y 3次のように , で区切って並べても同じ結果が得られます。 # gnuplot> splot x*x+sin(y), -x*x+y*y #2次元と同様に w d, w l, w i が使えます。 # gnuplot> splot x*x+sin(y) w d # gnuplot> splot x*x+sin(y) w l # gnuplot> splot x*x+sin(y) w i #gnuplot> plot sin(x) title 'my title' #gnuplot> plot sin(x) notitle #gnuplot> set terminal png #gnuplot> set output "img-sin.png" #gnuplot> plot sin(x) w l #gnuplot> set terminal png #gnuplot> set output "/dev/null" #gnuplot> plot sin(x) w l #gnuplot> replot cos(x) w l #gnuplot> set output "img-sincos-new.png" #gnuplot> replot tan(x) w l #データファイルdatafileの各行にx yの値 を並べることで、plot "datafile" としてグラフを描く ことができました。 #もとのデータファイルに2つ以上の数値があった場 合、最初の2つの値だけを使ってグラフが描かれます。 #2つ以上の数値が 保存されているdatafileに対し、3番目の データをx座標、2番目のデータを #y座標としてグラフを描くには次のようにします。 splotでも同様の使い方ができます。 #gnuplot> plot "datafile" using 3:2 #gnuplot> splot "datafile" using 3:2:7 #グラフの表示にはlineとpoint使った表示があります。デフォルトは lineです。 # gnuplot> plot sin(x) w[ith] l[ine] # gnuplot> plot sin(x) w l l[ine]t[ype] 4 # gnuplot> plot sin(x) w l l[ine]t[ype] 4 l[ine]w[idth] 3 3線種(linetype)、線幅(linewidth)が変更できます。ltやlwの後の数値 で指定します。 #なお、ディスプレイ上ではline typeは色の指定になり ますが、たとえばpostscriptに出力するときには破線等の指定となりま す。 # gnuplot> plot sin(x) w[ith] p[oint] # gnuplot> plot sin(x) w p p[oint]s[ize] # gnuplot> plot sin(x) w p p[oint]s[ize] 3 p[oint]t[ype] 4 #点の大きさ、点種が変更できます。psやptの後の数値で指定します。 #縦横を半分のサイズ(面積で1/4)にするには、set size で縦横 の縮尺を0.5に指定します。 # gnuplot> plot sin(x) # gnuplot> set size 0.5, 0.5 # gnuplot> plot sin(x) #新しめのgnuplotではsizeをsquareにするこ とで、正方形のグラフにできます。 # gnuplot> set size square # gnuplot> plot sin(x) gnuplot> plot sin(x) with dot とすると、グラフが小さな点で描かれます。 gnuplot> plot sin(x) w d と省略できます。 gnuplot> plot sin(x) with line gnuplot> plot sin(x) w l では、点を線で結んだグラフになります。 gnuplot> plot sin(x) with impulse gnuplot> plot sin(x) w i はインパルス表示です。 gnuplot> set parametric gnuplot> f(x,y) = x**2+y**2 gnuplot> splot f(x,y) gnuplot> splot u,v,f(u,v) gnuplot> splot u,v,u**2+v**2 とすれば、どちらでも最初の例と同じグラフを得ることができます (x,y,z) = (u,2u,3u) でした。gnuplotでもこれをそのまま使って、 gnuplot> splot u,2*u,3*u とすることができます。媒介変数として v をつかってもかまいません。 gnuplot> splot v,2*v,3*v 螺旋は次のようにして表示できますね。 gnuplot> splot u,sin(u),cos(u) 例として、曲面をある平面で切った状況で、その切口を表示してみます。 まずは双曲面を切ってみましょう。 gnuplot> f(x,y) = (x**2-y**2)/2 gnuplot> set zrange [-7:7] # 見かけをととのえるため。 gnuplot> splot u,v,f(u,v) # 曲面 gnuplot> replot 2,v,u # 平面 gnuplot> replot 2,v,f(2,v) # 切口の曲線 X軸やY軸が2系統あるグラフ 比較的新しい gnuplot (version 3.6以降?)では、Y軸の刻みを2通りに 刻めます。 gnuplot> set y2tics gnuplot> set y2range [-5:15] gnuplot> plot sin(x), cos(x) axes x1y2 gnuplot> plot sin(x) axes x1y2, cos(x) axesの引数には x1y1, x1y2, x2y1, x2y2 の何れかが指定できます。 set y2ticsの代わりにset x2ticsを指定すれば、X軸が2系統になります。 gnuplot> set x2tics gnuplot> set x2range [-5:5] gnuplot> plot sin(x), cos(x) axes x2y1 gnuplot> plot sin(x) axes x2y1, cos(x) もちろん、y2ticsとx2ticsは混在できます。 gnuplot> set x2tics; set y2tics gnuplot> set x2range [-5:5]; set y2range [-5:5] gnuplot> plot sin(x) axes x1y1, cos(x) axes x2y2 なお、想像通りset xrangeやset yrangeを使って、x1やy1の範囲を変更 できます。これは2系統のX軸やY軸が不要の場合でも使えます。 対話を開始する: gnuplot 2 つのコマンドファイル "input1", "input2" を使ってバッチ処理を行なう: gnuplot input1 input2 初期化ファイル "header" の後、対話型モードを起動し、その後別のコマンドファイル "tailer" を実行する: gnuplot header - trailer コマンドラインから gnuplot コマンドを直接与え、終了後にスクリーン上にグラフが残るようにオプション "-persist" を使う: gnuplot -persist -e "set title 'Sine curve'; plot sin(x)" ファイルのコマンドを実行する前に、ユーザ定義変数 a と s をセットする: gnuplot -e "a=2; s='file.png'" input.gpl