プログラミング/Gnuplot
[
Front page
] [
New
|
List of pages
|
Search
|
Recent changes
|
Help
] [
Japanese
/
English
]
Research
research overview
papers
media
Members
professors
graduates
undergraduates
alumni
Links
Links
Classes
Computer Programming Basic II
Special Lecture of Mechanical Intelligent System Engineering I
Start:
[[プログラミング]]
#contents
*Gnuplotとは [#s8defca8]
二次元、三次元のグラフを作成するためのコマンドラインアプ...
-入力した数式やテキストファイルなどから、画面もしくは画像...
-Linux,UNIX,Windows,Mac OS Xなど多くのOSに対応
*基本的な使い方 [#hdccf123]
-コマンドラインで"gnuplot"と打つと起動する.
-直線 y = 2x+1 を引く
plot 2*x+1;
-テキストファイルからデータを読み込んでプロット
plot "filename"
-テキストファイルからデータを読み込んで,データ点をつない...
plot "filename" with lines
-以上のデータ形式は,以下のようなタブorスペース区切り形式
0.0 1
0.1 5.4
0.2 8.3
...
*ちょっと応用編 [#i434a862]
-複数のファイルからデータを読み込んで,同じグラフにプロット
plot "filename1" with lines, "filename2" with lines
もしくは
plot "filename1" with lines,\
"filename2" with lines
でも同じ
-以下のようなデータ(例えば 時間 角度 角速度 の順に並...
0.0 1 0
0.1 5.4 32
0.2 8.3 43
...
plot "filename" using 1:3 with lines
-epsへ書き出す:サンプルファイル&ref(本堂/data2eps.gnu); ...
-同じファイルから複数のデータを読み込んで,同じグラフにプ...
-- (time data[0] data[1] ... data[n])みたいな順番だったと...
-- 2列目からn列目まで
plot for [i=2:n] "filename" using 1:i with lines
-- 2列目,4列目,9列目など跳び跳びに
plot for [i in "2 4 9"] "filename" u 1:i w l
*3次元編 [#e298e7f2]
-3次元のデータを普通にsplotでグラフにすると,点や線のグラ...
set dgrid3d 30,30 (30はメッシュの数.多くするとなめらか...
set hidden3d
splot "dkjkfajsjfalk.dat" using 1:2:3 with lines
*応用編 [#ra67aafa]
**gnuplotをCのプログラムから制御する [#c9c3592d]
-popen()関数を用いてCのプログラムからgnuplotへパイプを通...
-流れ
--コマンドとなるポインタgpを作り、それに実行したいコマン...
FILE *gp;
・・・
gp=popen("gnuplot","w");
・・・
fprintf(gp,"コマンドの引数\n");
・・・
Pclose(gp);
-ex.計算結果からdatファイルとグラフの作成
--サンプル&ref(gnuplot_sample1.c);
**gnuplotで最小自乗法 [#p7cbff6a]
-fitコマンドを使うことで関数に対しデータフィッティングを...
-パラメータを含んだ関数を用意すると,データファイルの数値...
-関数はgnuplotで表現できるものなら,線形・非線形を問わない
-流れ
--データファイルを用意.それにフィットさせる関数を定義し、...
f(x)=a*x+b
fit f(x) "exp.dat" via a,b //viaの後には求めたいパラメ...
-ex.一次関数でfit [#yedaa257]
--サンプル&ref(gnuplot_sample2.c);
**BoundingBox編集によるグラフのレイアウトの調整 [#ae84642d]
-epsファイルとして出力したグラフをLaTeXやパワポに載せる際...
-そのような場合はファイル中のBoundingBoxというパラメータ...
-流れ
--epsファイルをemacsなどで開き、BoundingBoxというパラメー...
--たとえば軸の位置ずらしたい場合,CTRL+Sなどで軸名を検索、...
--軸名の上に数字が二つ並んでいるところがあり、その数字を...
&aname(EusLisp);
*EusLisp 編 [#t6141ec7]
(setq g (gnuplot)) ;;gnuplotの白紙のグラフが出る。
(send g :plot '("file.dat" "using 1:6") :xrange '(-1 1) ...
;;gnuplot> plot [-1:1][0:5] "file.dat" using 1:6 with...
(send g :plot '("file.dat" "using 1:2") '("file.dat" "us...
(defun plot-indexes (file indexes)
(let (args entry)
(setq args nil)
(dolist (index indexes) ;;indexesというリストの要...
(setq entry (list file (format nil "using 1:~A" i...
(push entry args) ;;entry をargsというリストの先...
);;dolist終わり
(setq args (nreverse args)) ;;argsを逆順にする。
(send* g :plot args)))
(plot-indexes "file.dat" (list 2 4 6 7 8))
End:
[[プログラミング]]
#contents
*Gnuplotとは [#s8defca8]
二次元、三次元のグラフを作成するためのコマンドラインアプ...
-入力した数式やテキストファイルなどから、画面もしくは画像...
-Linux,UNIX,Windows,Mac OS Xなど多くのOSに対応
*基本的な使い方 [#hdccf123]
-コマンドラインで"gnuplot"と打つと起動する.
-直線 y = 2x+1 を引く
plot 2*x+1;
-テキストファイルからデータを読み込んでプロット
plot "filename"
-テキストファイルからデータを読み込んで,データ点をつない...
plot "filename" with lines
-以上のデータ形式は,以下のようなタブorスペース区切り形式
0.0 1
0.1 5.4
0.2 8.3
...
*ちょっと応用編 [#i434a862]
-複数のファイルからデータを読み込んで,同じグラフにプロット
plot "filename1" with lines, "filename2" with lines
もしくは
plot "filename1" with lines,\
"filename2" with lines
でも同じ
-以下のようなデータ(例えば 時間 角度 角速度 の順に並...
0.0 1 0
0.1 5.4 32
0.2 8.3 43
...
plot "filename" using 1:3 with lines
-epsへ書き出す:サンプルファイル&ref(本堂/data2eps.gnu); ...
-同じファイルから複数のデータを読み込んで,同じグラフにプ...
-- (time data[0] data[1] ... data[n])みたいな順番だったと...
-- 2列目からn列目まで
plot for [i=2:n] "filename" using 1:i with lines
-- 2列目,4列目,9列目など跳び跳びに
plot for [i in "2 4 9"] "filename" u 1:i w l
*3次元編 [#e298e7f2]
-3次元のデータを普通にsplotでグラフにすると,点や線のグラ...
set dgrid3d 30,30 (30はメッシュの数.多くするとなめらか...
set hidden3d
splot "dkjkfajsjfalk.dat" using 1:2:3 with lines
*応用編 [#ra67aafa]
**gnuplotをCのプログラムから制御する [#c9c3592d]
-popen()関数を用いてCのプログラムからgnuplotへパイプを通...
-流れ
--コマンドとなるポインタgpを作り、それに実行したいコマン...
FILE *gp;
・・・
gp=popen("gnuplot","w");
・・・
fprintf(gp,"コマンドの引数\n");
・・・
Pclose(gp);
-ex.計算結果からdatファイルとグラフの作成
--サンプル&ref(gnuplot_sample1.c);
**gnuplotで最小自乗法 [#p7cbff6a]
-fitコマンドを使うことで関数に対しデータフィッティングを...
-パラメータを含んだ関数を用意すると,データファイルの数値...
-関数はgnuplotで表現できるものなら,線形・非線形を問わない
-流れ
--データファイルを用意.それにフィットさせる関数を定義し、...
f(x)=a*x+b
fit f(x) "exp.dat" via a,b //viaの後には求めたいパラメ...
-ex.一次関数でfit [#yedaa257]
--サンプル&ref(gnuplot_sample2.c);
**BoundingBox編集によるグラフのレイアウトの調整 [#ae84642d]
-epsファイルとして出力したグラフをLaTeXやパワポに載せる際...
-そのような場合はファイル中のBoundingBoxというパラメータ...
-流れ
--epsファイルをemacsなどで開き、BoundingBoxというパラメー...
--たとえば軸の位置ずらしたい場合,CTRL+Sなどで軸名を検索、...
--軸名の上に数字が二つ並んでいるところがあり、その数字を...
&aname(EusLisp);
*EusLisp 編 [#t6141ec7]
(setq g (gnuplot)) ;;gnuplotの白紙のグラフが出る。
(send g :plot '("file.dat" "using 1:6") :xrange '(-1 1) ...
;;gnuplot> plot [-1:1][0:5] "file.dat" using 1:6 with...
(send g :plot '("file.dat" "using 1:2") '("file.dat" "us...
(defun plot-indexes (file indexes)
(let (args entry)
(setq args nil)
(dolist (index indexes) ;;indexesというリストの要...
(setq entry (list file (format nil "using 1:~A" i...
(push entry args) ;;entry をargsというリストの先...
);;dolist終わり
(setq args (nreverse args)) ;;argsを逆順にする。
(send* g :plot args)))
(plot-indexes "file.dat" (list 2 4 6 7 8))
Page: