gnuplot
作成:2000-03-21
更新:2003/06/19
linux環境だと大抵入っているし、気の利いたunix環境だと絶対に入ってます(笑)。
gnuplotは'GNU'プロジェクトではありませんのでGNUplotではなく、gnuplotでして、所謂フリーソフトです。
(GNUプロジェクトだと”ぐにゅ〜"と読むらしんだけど、そうじゃないとするとこれは"ニュープロット"と読むべきか?
僕はgnuplotと読んでますが(笑)
Windows版は http://www.yama-ga.com/gnuplot/
あたりから日本語+拡張パッケージが入手出来るようです。
Windows版の実行ファイルは wgnuplot.exe という名前になっている様です。
使い方は、その辺のポータル(yahoo , goo , infoseek )から gnuplot を検索すれば、いろいろな人が書いていますのでそれ見てください。
…といったら、あんまりなので…
Tips
( G N U P L O T MS-Windows 32 bit version 3.7 patchlevel 1 (+1.1.9
1999/11/08) last modified Fri Oct 22 18:00:00 BST 1999 )
のバージョンに対するTipsです。
C:\data\ というフォルダに xy.dat というデータファイルが
#x y 1 2 2 4.5 3 5.5 4 6.5 5 6.7 6 7.0 |
ってな感じで入っているとします。(gnuplotは#の行は無視して読みます)
|
#ディレクトリをデータのディレクトリにして、単に点でプロットしてみる gnuplot> cd 'C:\data' gnuplot> plot 'xy.dat'
|
![]() |
|
#データ点を線で結んでみる gnuplot> plot 'xy.dat' with linespoint |
![]() |
|
#x,yの範囲をautoscale じゃなくて、指定してみる gnuplot> plot [0:8] [0:10] 'xy.dat' with points |
![]() |
|
#点の形とサイズも指定する。 gnuplot> plot [0:8] [0:10] 'xy.dat' with points pointtype 8 pointsize 2.2 |
![]() |
|
# 主目盛(xtics)と副目盛(mxtics)も指定。 gnuplot> set xtics 0,2,10 ; set mxtics 10 ; set ytics 0,1,10 ; set mytics 10 ;set ticscale 3 1 ; replot #グリッドもつける。タイトルもつける。 gnuplot> set grid ; replot set title 'demo for gnuplot' ; set xlabel 'x-axis' ; set ylabel 'y-axis' 0.5,0.5 ; replot #フォントをTerminal等にしておかないと、何故かylabelが出ない様だ? |
![]() |
|
# acspline (approximates cubic splines?)でスプライン近似してみる。 gnuplot> plot [0:8] [0:10] 'xy.dat' with points pt 8 ps 1.5 ,'xy.dat' using 1:2:(1) smooth acsplines ; # 2個データを書いたら、keyが詰まっちまったので、広げる。 |
![]() |
|
#ちなみにacsplinesのウェイトを大きくするとデータを意地でも通るスプラインになる様だ。 gnuplot> plot [0:8] [0:10] 'xy.dat' with points pt 8 ps 1.5 ,'xy.dat' using 1:2:(100) smooth acsplines ;
|
![]() |
|
#fit関数で曲線の当てはめを行う。任意のf(x)を準備しておき、初期値も適当に設定しておく。(設定しなくてもよいが、ヘタすると収束しないので、適当でいいから設定しておくほうがよい) gnuplot> f(x) = a*(1-exp(-b*x)) #a,bについてfit計算を行う(収束するまで画面が流れる) gnuplot> fit f(x) 'xy.dat' using 1:2 via a,b #計算後、グラフを重ねる。 gnuplot> plot [0:8] [0:10] 'xy.dat' with points pt 8 ps 1.5 ,'xy.dat' using 1:2:(100) smooth acsplines title '(acsp)' , f(x) #keyを調整してboxで囲んでみる。 gnuplot> set key left samplen 6 spacing 6 width 8 box ; replot #収束したa,bの値を表示させ、矢印(arrow)とラベルを付けてみる。arrowのlinetypeはこの場合は色を示す。 gnuplot> print a,b |
set xtics 0,2,10 ; set mxtics 10 ; set ytics 0,1,10 ; set mytics 10
;set ticscale 3 1 ; set grid f(x) = a*(1-exp(-b*x)) fit f(x) 'xy.dat' using 1:2 via a,b plot [0:8] [0:10] 'xy.dat' with points pt 8 ps 1.5 ,'xy.dat' using
1:2:(100) smooth acsplines title '(acsp)' , 7.961*(1-exp(-0.3823*x))
title 'f(x)'; print a,b |
|
さらに硬派な人は set terminal latex で set output 'fx.tex'
とかすると今週は満足感上昇中でしょう。(右図)
\begin{document} |
set size nosquare 0.6,0.8 plot [0:10][0:8] 'xy.dat' title 'xy' w p pt 8 ps 2 , 'xy.dat' using 1:2:(1000) smooth acsplines title '(acsp)' , 7.961*(1-exp(-0.3823*x)) title 'f(x)'; set arrow 1 from 4.2,2.5 to 2.6,5.0 lt 3 set output 'fx.tex' ;set terminal latex ; replot set output 'stdout' ; set terminal win #LaTeXの制御記号の \を\\って書くところがミソ
|
|
金持ちな人はPostScriptなカラープリンタで直接うっちまえ〜。元々PostScriptプリンタなんて無い普通の人(僕も)はこんな面倒な事をする意味が見出せませんもの。(GSview 2.7 とかの PostScript previewerを使って見るしかないし). |
set size nosquare 1,1 plot [0:10][0:8] 'xy.dat' title 'xy' w p pt 7 ps 2.2 , 'xy.dat' using
1:2:(1000) smooth acsplines title '(acsp)' , 7.961*(1-exp(-0.3823*x))
title 'f(x)'; set arrow 1 from 4.2,2.5 to 2.6,5.0 lt 3 ; replot set output 'post.ps' ;set terminal postscript plus color
"Helvetica" 35 ; replot set output 'stdout' ; set terminal win #LaTeXの制御記号の \を\\って書くのはLaTeXに同じ |
|
その他
|