graphics

「graphics」の編集履歴(バックアップ)一覧はこちら

graphics」(2019/05/13 (月) 00:19:08) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

#contents() (参考)[[gnuplotの解説(米澤進真吾)>>http://www.ss.scphys.kyoto-u.ac.jp/person/yonezawa/contents/program/gnuplot/]] [[GNUPLOT 4.2 - A BRIEF Manual and Tutorial (Duke Univ.)>>http://people.duke.edu/~hpgavin/gnuplot.html]] [[LATEX and the Gnuplot Plotting Program>>http://gnuplot.info/files/tutorial.pdf]] *gunuplot 入門(windows版)2008/5/9 **入門編 1.windows版gnuplot binaries included: * wgnuplot.exe: The default executable * wgnuplot_pipes.exe: plot `<awk -f change.awk data.dat' * pgnuplot.exe: accept commands on stdin and pipe them to an wgnuplot text winodw. (注)角藤版では、wgnuplot_pipes.exeが含まれていない。 Gnuplot 4.3 patch level 0 の Windows 用バイナリです (開発中の版)。 pdf.trm with pdflib を採りこんであります。最新の lua terminal も使用可にしてあります。 --- wgnuplot.exe --- 通常の GUI 版 --- wgnuplot_pipes.exe --- popen(), pclose() をサポートする GUI 版 --- gnuplot.exe --- 標準入出力の利用、popen(), pclose() が可能な CUI版 --- pgnuplot.exe --- wgnuplot.exe を使って標準入出力を利用する簡易 CUI版 (updated on 2009/04/19) 2.環境設定 (1)フォントの設定  右クリックでchoose font でMSゴシック。さらに、updateする。 (2)パス指定  コマンドプロンプトでも使うために、パス指定を行う。  実行ファイルは wgnuplot.exe (コマンドプロンプト上でwgnuplotと入力すると起動)   3.作業ディレクトリへの移動 gnuplot> cd 'd:\home' : cd to d:\home (注)single quoteを用いること gnuplot> pwd : print working diretory 4.gnuplotでできること (1)描く ・関数のグラフを描く(2次、3次) ・データのプロット ・グラフ上での日本語入力(タイトル等):グラフ上で右クリックでchoose fontで日本語表示。 ・複数のグラフ plot x, sin(x) ・replot 再描画。オプションを変えた後、再度グラフ表示。 (2)入出力 ・入力(データ、バッチ処理用スクリプト)load 'script' ・グラフの出力(eps,latex等)(windows用:右クリックでcopy to clipboard) epsへの出力 plot ...; set term[inal] pos[tscript] eps enhanced; set output 'data.eps'; rep; # epsファイル名を設定。epsに。 set term windows; set output # 元に戻す ・グラフの印刷 (windows用:右クリックでPrint)      (白黒プリンターの場合、右クリックでColorのチェックを外して、モノクロにしておく。) 5.終了 ・exit または quit 6.グラフの利用 ・epsをlatexで利用 ・他のwindows アプリケーションで利用(右クリックでcopy to clipboard) 7.ヘルプ  h[elp] : 項目一覧  h[elp] p[lot] : プロット参照  h[elp] new : 新機能参照 8.コマンド入力・シェル  !command : command実行  shell : シェルへ(exitで戻る) -------------------------------------------------------------------------------------- **応用編 1.関数 ・組み込み関数 help functionsで一覧 sin(x),log(x),log10(x),exp(x),sqrt(x),erf(x) ・polynomial ** is used for exponentiation (as in FORTRAN) ・^ はlogical operaterで binary bitwise ANDの意味 2.プロット (1)command p[lot] : 2-d functions and data splot : 3-d surfaces and data rep[lot] : repeat the last plot or splot  clear : remove objects in the canvas (2)syntax plot {[range]} {[function] | {'[datafile]' {datafile-modifiers}}} {axes [axes] } { [title-spec] } {with [style]} {, {definitions, } [function] ...} -> help plot, help plot with, help plot using, help plot smooth (3)plotting functions gnuplot> plot sin(x) title 'Sine Function', tan(x) title 'Tangent' gnuplot> splot sin(x*y/20) (4)data plotting ------force.dat------------ # This file is called force.dat # Force-Deflectin data for a beam and a bar # Deflection Col-Force Beam-Force 0.000 0 0 0.001 104 51 0.002 202 101 0.003 298 148 0.0031 290 149 0.004 289 201 0.0041 291 209 0.005 310 250 0.010 311 260 0.020 280 240 (注)column間はtab,spaceのみ gnuplot> plot 'force.dat' using 1:2 title 'Column', \ '' using 1:3 title 'Beam' (注)継続行は \  ''は前と同じファイルを示す(file名は、'でも"も可) help plot datafile (注2)データの値が1行に1つの場合、上からx=0,1,2,...の場合のyの値と判断する。 (注3)空白行がある場合、線が途切れる。 (注4)区切り文字(csv形式)などは""で指定。例)set test1_2.dat separator ","  ---datafile  datafile="./plotdata.txt" (○ plot "../work/gp/data" 、× plot "~/foo/gp/data")  set terminal png  set output "points.png"  plot datafile using 1:2 with points # 線でつなぐなら with linespoints #3列のデータなら using 1:2:3  pause -1 "Hit any key to continue" (5)plot の種類 styles : lines, points,dots,histgrams and so on --> help style gnuplot> plot 'force.dat' using 1:2 title 'Column' with lines, \ '' u 1:3 t 'Beam' w linepoints (6)図の調整 (set command) set title "Force-Deflection Data" set xlabel "Deflection (meters)" set ylabal "Force (kN)" set xrange [0.001:0.005] set yrange [20:500] set autoscale set key 0.01, 100 unset key set label "yield point" at 0.003, 260 unset label set logscale (x,xy,z) # (x軸、xy軸、z軸) unset logscale; set logscale set xtics (0.002,0.004,0.006,0.008) unset xtics; set xtics auto その他のset arrow, border, clip, contour, grid, mapping, polar, surface, time, view... (7)script -------force.p---------------------- # Gnuplot script file for plotting data in file "force.dat" # This file is called force.p set autoscale # scale axes automatically unset log # remove any log-scaling unset label # remove any previous labels set xtic auto # set xtics automatically set ytic auto # set ytics automatically set title "Force Deflection Data for a Beam and a Column" set xlabel "Deflection (meters)" set ylabel "Force (kN)" # set key 0.01,100 ----> やってみると受け付けない。 set label "Yield Point" at 0.003,260 set arrow from 0.0028,250 to 0.003,280 set xr [0.0:0.022] set yr [0:325] plot "force.dat" using 1:2 title 'Column' with linespoints , \ "force.dat" using 1:3 title 'Beam' with points -------------------------------------------------- スクリプトの実行 gnuplot> load 'force.p' スクリプトの保存 gnuplot> save 'xxxx.plt' (8)comment characters set datafile commentschars "#%" (9)curve-fitting f1(x) = a1*tanh(x/b1) a1 = 300;b1=0.005; # initial guess fit f1(x) 'force.dat' u 1:2 via a1,b1 f2(x)=a2*tanh(x/b2) a2=300;b2=0.005; fit f2(x) 'force.dat' u 1:3 via a2,b2 # set key 0.018,150 title "F(x) = A tanh (x/B)" -->受け付けない。 set title 'Force Deflectin Data \n and curve fit' # pointsize 1.5 --> 受け付けない。 set xlabel 'Deflection, {/Symbol D}_x (m)' set ylabel 'Force, {/Times-Italic F}_A, (kN)' plot 'force.dat' u 1:2 t 'Column data' w p 3,\ '' u 1:3 t 'Beam data' w p 4,\ a1*tanh(x/b1) t 'Column-fit: A=309, B=0.00227',\ a2*tanh(x/b2) t 'Beam-fit: A=260, B=0.00415' (注)w p の後の数値は受け付けなかった。 (10)グラフの出力 eps gnuplot> set term[inal] postscript eps enhanced gnuplot> set output "test.eps" gnuplot> set key left top gnuplot> set size 0.5, 0.5 gnuplot> set xrange [0:4] gnuplot> set yrange [0:4] ------------------- gnuplot> plot 0.2536*x+1.1717 title "lesq fit" w lines linestyle 1,\ "test.dat" u 1:2:3 t "data" w yerrorbars linestyle 2 gnuplot>unset term # windows では set terminal windows gunplot>unset output # windows?では、set outputでよい。なぜか。 -------- latex文書--------------------------------------------------- \documentclass{article} \usepackage[dviout]{graphicx} \begin{document} # \maketitle \begin{figure}[htbp] \begin{center} # \resizebox{120mm}{!}{\includegraphics[scale=0.5]{test.ps}} \includegraphics[width=9cm]{test.ps} \caption{This is a sample figure.} \label{test} \end{center} \end{figure} \end{document} (11)欄の数値を計算してとりこむ p 'force.dat' u (3*$2):(sin($3+$1)) (12)multi-plot 複数のグラフを1枚に set multiplot set size 1,0.5 set origin 0.0,0.5; p sin(x); set origin 0.0,0.0 ; p cos(x) unset multiplot 今までの設定をキャンセルするには? reset ただし、terminalとoutputはデフォルト値に戻されない。 (13)hard-copy(plotting on paper) # File name: save.plt - save a Gnuplot plot as a PostScript file # to save the current plot as a postscript file issue the commands: # gnuplot> load 'saveplot' # gnuplot> !mv my-plot.ps another-file.ps set size 1.0, 0.6 set terminal postscript portrait enhanced mono dashed lw 1 "Helvetica" 14 set output "my-plot.ps" replot set terminal x11 set size 1,1 # set terminal postscript {<mode>} {enhanced | noenhanced} # {color | colour | monochrome} # {blacktext | colortext | colourtext} # {solid | dashed} {dashlength | dl <DL>} # {linewidth | lw <LW>} # {<duplexing>} # {"<fontname>"} {<fontsize>} # set terminal gif {transparent} {interlace} # {tiny | small | medium | large | giant} # {size <x>,<y>} # {<color0> <color1> <color2> ...} # set terminal png # {{no}transparent} {{no}interlace} # {tiny | small | medium | large | giant} # {font <face> {<pointsize>}} # {size <x>,<y>} {{no}crop} # {{no}enhanced} # {<color0> <color1> <color2> ...} gnuplot> load 'save.plt' gnuplot> !mv my-plot.ps force.ps gnuplot> !lpr force.ps (14)printing two figures on one page -------cat2(executable)------- chmod +x cat2 # cat2: Shell script for putting two Gnuplot plots on one page echo %! > g.ps echo gsave >> g.ps echo 0 400 translate >> g.ps # for Gnuplot plots cat $1 | sed -e "s/showpage//" >> g.ps echo grestore >> g.ps echo gsave >> g.ps echo 0 090 translate >> g.ps # for Gnuplot plots cat $2 >> g.ps lpr -Phudsonlp1 g.ps plot1.ps とplot2.psを1枚に ==> cat2 plot1.ps plot2.ps ------------------------------------------------------------------------------- **例 1.関数プロット p sin(x),cos(x) : 2つの関数をplot 2.データプロット p 'data.dat' w e, 0.25*x+9.0 :エラーバー表示+直線 p '' u 1:($2*$3) : 1:(cos($2)*$3) (cos($1)):((cos($2)*$3) f(x,a,b)=a*x*tanh(b*x) p '' u 1:(f(x, p 'data.dat' w[ith] l[ines] : 線を引く p 'data.dat' t 'データプロット' w p :点でプロット。タイトル p 'data1.dat' t '○○' w p, 'data2.dat' t '××' w lp : 2系列をプロット p 'data.dat' u[sing] 1:2 w lp : 1列目と2列目のデータを使う p [100:300] 'data.dat' : x軸の領域設定 p [100:300] [*:0] 'data.dat' : x軸の領域、y軸の上限を設定。*はautoscale p [-2*pi:2*pi] cos(x) p [] [-2:2] cos(x) 3.グラフの設置 set <-> unset set xr[ange] [aa:bb] set yr[ange] [aa:bb] set grid set xtics 1.1,0.1,1.3 : x軸の目盛りを1.1から1.3まで0.1刻みに set xtics (1.1,"PI/2" pi/2, 1.3) set logscale x(y) : X軸(y軸)をログスケールに set xlabel 'X-Axis' set ylabel 'Y-Axis' set nozreo : x軸とy軸のゼロのところの点線を引かない。 set autoscale x : x軸の範囲を自動に。 show all show title 4.データの空白行の扱い  ・空白行が1行の場合 連結して描画しない。  ・空白行が2行の場合 index オプションにより、異なるデータ列として扱う。   例 p 'sep.dat' index 0 t 'index 0' w p, '' index 1 t 'index 1' w l 5.描画のdefault設定  ・データ描画を点から線にする set data style lines  ・関数の描画を線にする set style function lines   6.線 (1)line option ・pt,pointtype :形(丸、四角) ・ps,pointsize :大きさ ・lt,linetype :カラー、白黒 ・lw,linewidth :太さ (2)線種の手動設定(白黒印刷時) set linestyle 1 lt 1 lw 1.0 set linestyle 2 lt 1 lw 2.0 p 'data.dat' u 1:2 w l linestyle 1,'' u 1:3 t 'graph2' w l 1 linestyles2 set linestyle 1 lt 1 lw 1.0 pt 2 ps 5.0 set linestyle 2 lt 1 lw 2.0 pt 7 ps 1.0 7.データの結び方 p 'data.dat' smooth csplines (unique,bezier) キュービックスプライン曲線(線形補間という直線、ベジェ曲線)で結ぶ。 8.エラーバー w xyerrorbars 想定のデータ構造 X Y dX dY または X Y X1 X2 Y1 Y2 p 'data.dat' u 1:2:3 w yer pt 7 (データのポイント部分を塗りつぶしの丸とする) 9.タイトルなど (1)タイトルを消す  全体のタイトルなら set title 各データなら p 'sin.dat' notitle w l (2)タイトルの位置 set key bottom グラフの下 set key left 左へ set key left bottom(top) 左下(上) set key 220,0.4 グラフがx軸・y軸座標の単位で(220,0.4)に位置させる 10.ラベル (1)軸 set xlabel 'X-label' set xlabel ラベルを消す  set xlabel "{/=30 Temperatrue (K)}" 30ポイント  set ylabel "{/=30 REsistivity ({/Symbol mW} cm)}" 30pts, ギリシア文字 マイクロ、モー  set ylabel "{/=30 {/Symbol-Oblique r}_{/Arial-Italic c} ({/Symbol mW}cm)]" ギリシア文字など30ポイント (2)文字列 set label '(0,0), center-just.' at -7,0.8 グラフ座標で(-7,0.8)の位置に左寄せで                 at -7,0.8 center(right) 中央寄せ(右寄せ) set arrow form -7,0.8 to 0,0 lt 2 lw 2 set label 'label' at X,Y font 'Helvetica,24' 文字列のフォントを指定 set nolabel, set noarrow 全体を消す show label, show arrow で番号を確認し、特定のものだけを消すことができる。 11.グラフの大きさ set size 2 x軸、y軸を2倍にする set size 1,3 y軸のスケールをx軸の3倍に(縦に拡大) set size square 4 正方形のまま4倍に set size ratio 2 y軸をx軸に対して2倍に拡大 set size ratio -1 x軸とy軸の単位を揃える。地図上でのデータの表示など 12.軸の目盛り set xtics INCR 増分値をINCRに設定 set xtics START, INCR[, END] 目盛りの最初、増分値、(終わり) set xtics ('START' 0, 'MIDDLE' 250, 'END' 500) 目盛りの位置と表示文字の設定  set xtics pi  set format x "%.0PPi" もしくは set formatx "%.0PPi"  plot [0:4*pi] sin(x) w l 数値表示桁数の設定 set format x "%7.3f" 全体7桁、小数点以下3桁 set xtics (1.1,pi/2,1.3) rep 戻す set xtics    13.データの扱い (1)データ列 plot 'multi.dat' using ($1-$3) w l p 'multi.dat' u 1:(valid(2) ? $2 : 1/0) 無効なデータを無視する (2)特殊なデータ列 $0 データ行ごとに増加し、連続空白2行で0にリセット $-1 空行ごとに増加し、連続空白2行で0にリセット $-2 連続空白2行ごとに増加 データ形式に,が使われている場合 p 'ugly.dat' using 1:2 "%l%f*[, ]%lf" はじめの値を1列目、続くカンマもしくはスペースをすべて無視し、次の実数値を2列目とする。 call の場合、$1がパラメータと解釈されるので、colunmn(n)で第n列目を指定する。 14.その他 print pi # 変数の表示 myfunc(t) = sin(t/T) p [t=-2*pi:2:pi] T=1,myfunc(t) t 'T=1' w l, T=2,myfunc(t) t 'T=2' w l #(関数の実体は定義時ではなく、実行時に評価される) set samples # 1000 関数プロットの点の数を設定する 15.3次元 splot [-5:5][-5:5] sin(sqrt(x**2+y**2)) set hidden3d 隠線処理 <-> set nohidden3d set contour base 等高線をxy平面に <-> set nocontour set isosamples 30 解像度を30に (default 10) 16.postscript enhanced a~{b} 上付き a_{b} 下付き a`^{b}_{c} 上下に付く {/Symbol G} ギリシャ文字ガンマの大文字 {/Symbol g} ギリシャ文字ガンマの小文字 対数プロットの目盛りを1,10,100から10^0,10^1,10^2のべき乗に変更 set terminal postscript enhanced set logscale y set format y "10^{%L}" set key spacing 1.4 p 'data.dat' u 1:2,t '{/Symbol G}_{a}','' u 1:3 t '{/Symbol r}^{b}' set terminal postscript enchanced 'Times-Roman' 14 #(Helvetica,Times-Roman,Courierなど、defaultはHelvetica 14) set t '{/Times-Roman=40 G} {/Courier=40 G} {/Helvetica=40} {/Symbol=40 G}' set t '{/Times-Roman*2.0 G} {/Courier*2.0 G} {/Helvetica*2.0 G} {/Symbol*2.0 G}' # フォントサイズを2倍に設定 set t '{/Helvetica e}^{- {/Courier i} {/Symbol g}^2}' (関連リンク) [[GNUPLOT ポータル>>http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/index-gnuplot.html]] [[Gnuplotの第一歩>>http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/gnuplot-intro/index.html]] [[グラフは Gnuplot にお任せ>>http://ayapin.film.s.dendai.ac.jp/~matuda/Gnuplot/]] [[GNUPLOT るさんちまん>>http://mibai.tec.u-ryukyu.ac.jp/~oshiro/Doc/gnuplot_primer/]] [[Gnuplot の点点 (Postscript出力)>>http://hosho.ees.hokudai.ac.jp/~kubo/memo/gnuplot-points.html]] [[Gnuplot - Scientific Plotting>>http://www.usf.uni-osnabrueck.de/~breiter/tools/gnuplot/index.en.html]] [[gnuplot のページ (Takeno Lab)>>http://takeno.iee.niit.ac.jp/~foo/gp-jman/gp-jman.html]] [[gnuplot入門(桂田祐史)>>http://www.math.meiji.ac.jp/~mk/labo/howto/intro-gnuplot/]] 2008.7.23 [[GNUPLOT FAQ>>http://t16web.lanl.gov/Kawano/gnuplot/index.html]] 2004/8/30 [[Gnuplot入門(半場滋)>>http://dsl4.eee.u-ryukyu.ac.jp/DOCS/gnuplot/index.html]] 2007/8/31 [[GNUPLOT FAQ>>http://folk.uio.no/steikr/doc/gnuplot/Kawano/index.html]] 2003/9/15 [[gnuplot入門(岡山大学情報工学科)>>http://www.suri.it.okayama-u.ac.jp/~niitsuma/j/lecture/gnuplot_nyuumon.html]] [[GNUPLOTの使い方>>http://nucl.sci.hokudai.ac.jp/~ohnishi/Education/compphys/LESSON/gnuplot.html]] [[Visualize your data with gnuplot(IBM)>>http://www.ibm.com/developerworks/library/l-gnuplot/]] [[GNUPLOT 4.2 - A Brief Manual and Tutorial>>http://www.duke.edu/~hpgavin/gnuplot.html]] Duke Univ [[Helping you with gnuplot>>http://www.gnuplot.info/help.html]] [[Plotting data using Gnuplot>>http://mathewpeet.org/computing/gnuplot/]] [[Gnuplot Tutorial>>http://physicspmb.ukzn.ac.za/index.php/Gnuplot_tutorial]] [[gnuplot fitting tutorial>>http://www.physics.ubc.ca/~phys209/files/gnuplot_tutorial2.pdf]] [[LATEX and the GNUPLOT Plotting Program>>http://skuld.bmsc.washington.edu/people/merritt/gnuplot/tutorial.pdf]] 1991.6 [[Plotting with Fortran 90>>http://www.phy.uct.ac.za/courses/phy400w/cp/f90tut.pdf]] [[Gnuplot-mode (for Emacs)>>http://homepage1.nifty.com/fin/soft/emacs/gnuplot-mode.html]] 2001/8/9
#contents() (参考)[[gnuplotの解説(米澤進真吾)>>http://www.ss.scphys.kyoto-u.ac.jp/person/yonezawa/contents/program/gnuplot/]] [[GNUPLOT 4.2 - A BRIEF Manual and Tutorial (Duke Univ.)>>http://people.duke.edu/~hpgavin/gnuplot.html]] [[LATEX and the Gnuplot Plotting Program>>http://gnuplot.info/files/tutorial.pdf]] *gunuplot 入門(windows版)2008/5/9 **入門編 1.windows版gnuplot binaries included: * wgnuplot.exe: The default executable * wgnuplot_pipes.exe: plot `<awk -f change.awk data.dat' * pgnuplot.exe: accept commands on stdin and pipe them to an wgnuplot text winodw. (注)角藤版では、wgnuplot_pipes.exeが含まれていない。 Gnuplot 4.3 patch level 0 の Windows 用バイナリです (開発中の版)。 pdf.trm with pdflib を採りこんであります。最新の lua terminal も使用可にしてあります。 --- wgnuplot.exe --- 通常の GUI 版 --- wgnuplot_pipes.exe --- popen(), pclose() をサポートする GUI 版 --- gnuplot.exe --- 標準入出力の利用、popen(), pclose() が可能な CUI版 --- pgnuplot.exe --- wgnuplot.exe を使って標準入出力を利用する簡易 CUI版 (updated on 2009/04/19) 2.環境設定 (1)フォントの設定  右クリックでchoose font でMSゴシック。さらに、updateする。 (2)パス指定  コマンドプロンプトでも使うために、パス指定を行う。  実行ファイルは wgnuplot.exe (コマンドプロンプト上でwgnuplotと入力すると起動)   3.作業ディレクトリへの移動 gnuplot> cd 'd:\home' : cd to d:\home (注)single quoteを用いること gnuplot> pwd : print working diretory 4.gnuplotでできること (1)描く ・関数のグラフを描く(2次、3次) ・データのプロット ・グラフ上での日本語入力(タイトル等):グラフ上で右クリックでchoose fontで日本語表示。 ・複数のグラフ plot x, sin(x) ・replot 再描画。オプションを変えた後、再度グラフ表示。 (2)入出力 ・入力(データ、バッチ処理用スクリプト)load 'script' ・グラフの出力(eps,latex等)(windows用:右クリックでcopy to clipboard) epsへの出力 plot ...; set term[inal] pos[tscript] eps enhanced; set output 'data.eps'; rep; # epsファイル名を設定。epsに。 set term windows; set output # 元に戻す ・グラフの印刷 (windows用:右クリックでPrint)      (白黒プリンターの場合、右クリックでColorのチェックを外して、モノクロにしておく。) 5.終了 ・exit または quit 6.グラフの利用 ・epsをlatexで利用 ・他のwindows アプリケーションで利用(右クリックでcopy to clipboard) 7.ヘルプ  h[elp] : 項目一覧  h[elp] p[lot] : プロット参照  h[elp] new : 新機能参照 8.コマンド入力・シェル  !command : command実行  shell : シェルへ(exitで戻る) -------------------------------------------------------------------------------------- **応用編 1.関数 ・組み込み関数 help functionsで一覧 sin(x),log(x),log10(x),exp(x),sqrt(x),erf(x) ・polynomial ** is used for exponentiation (as in FORTRAN) ・^ はlogical operaterで binary bitwise ANDの意味 2.プロット (1)command p[lot] : 2-d functions and data splot : 3-d surfaces and data rep[lot] : repeat the last plot or splot  clear : remove objects in the canvas (2)syntax plot {[range]} {[function] | {'[datafile]' {datafile-modifiers}}} {axes [axes] } { [title-spec] } {with [style]} {, {definitions, } [function] ...} -> help plot, help plot with, help plot using, help plot smooth (3)plotting functions gnuplot> plot sin(x) title 'Sine Function', tan(x) title 'Tangent' gnuplot> splot sin(x*y/20) (4)data plotting ------force.dat------------ # This file is called force.dat # Force-Deflectin data for a beam and a bar # Deflection Col-Force Beam-Force 0.000 0 0 0.001 104 51 0.002 202 101 0.003 298 148 0.0031 290 149 0.004 289 201 0.0041 291 209 0.005 310 250 0.010 311 260 0.020 280 240 (注)column間はtab,spaceのみ gnuplot> plot 'force.dat' using 1:2 title 'Column', \ '' using 1:3 title 'Beam' (注)継続行は \  ''は前と同じファイルを示す(file名は、'でも"も可) help plot datafile (注2)データの値が1行に1つの場合、上からx=0,1,2,...の場合のyの値と判断する。 (注3)空白行がある場合、線が途切れる。 (注4)区切り文字(csv形式)などは""で指定。例)set test1_2.dat separator "," (注5)複数のデータプロット plot "test1.dat" with linpoints, "test2.dat" with linpoints  ---datafile  datafile="./plotdata.txt" (○ plot "../work/gp/data" 、× plot "~/foo/gp/data")  set terminal png  set output "points.png"  plot datafile using 1:2 with points # 線でつなぐなら with linespoints #3列のデータなら using 1:2:3  pause -1 "Hit any key to continue" (5)plot の種類 styles : lines, points,dots,histgrams and so on --> help style gnuplot> plot 'force.dat' using 1:2 title 'Column' with lines, \ '' u 1:3 t 'Beam' w linepoints (6)図の調整 (set command) set title "Force-Deflection Data" set xlabel "Deflection (meters)" set ylabal "Force (kN)" set xrange [0.001:0.005] set yrange [20:500] set autoscale set key 0.01, 100 unset key set label "yield point" at 0.003, 260 unset label set logscale (x,xy,z) # (x軸、xy軸、z軸) unset logscale; set logscale set xtics (0.002,0.004,0.006,0.008) unset xtics; set xtics auto その他のset arrow, border, clip, contour, grid, mapping, polar, surface, time, view... (7)script -------force.p---------------------- # Gnuplot script file for plotting data in file "force.dat" # This file is called force.p set autoscale # scale axes automatically unset log # remove any log-scaling unset label # remove any previous labels set xtic auto # set xtics automatically set ytic auto # set ytics automatically set title "Force Deflection Data for a Beam and a Column" set xlabel "Deflection (meters)" set ylabel "Force (kN)" # set key 0.01,100 ----> やってみると受け付けない。 set label "Yield Point" at 0.003,260 set arrow from 0.0028,250 to 0.003,280 set xr [0.0:0.022] set yr [0:325] plot "force.dat" using 1:2 title 'Column' with linespoints , \ "force.dat" using 1:3 title 'Beam' with points -------------------------------------------------- スクリプトの実行 gnuplot> load 'force.p' スクリプトの保存 gnuplot> save 'xxxx.plt' (8)comment characters set datafile commentschars "#%" (9)curve-fitting f1(x) = a1*tanh(x/b1) a1 = 300;b1=0.005; # initial guess fit f1(x) 'force.dat' u 1:2 via a1,b1 f2(x)=a2*tanh(x/b2) a2=300;b2=0.005; fit f2(x) 'force.dat' u 1:3 via a2,b2 # set key 0.018,150 title "F(x) = A tanh (x/B)" -->受け付けない。 set title 'Force Deflectin Data \n and curve fit' # pointsize 1.5 --> 受け付けない。 set xlabel 'Deflection, {/Symbol D}_x (m)' set ylabel 'Force, {/Times-Italic F}_A, (kN)' plot 'force.dat' u 1:2 t 'Column data' w p 3,\ '' u 1:3 t 'Beam data' w p 4,\ a1*tanh(x/b1) t 'Column-fit: A=309, B=0.00227',\ a2*tanh(x/b2) t 'Beam-fit: A=260, B=0.00415' (注)w p の後の数値は受け付けなかった。 (10)グラフの出力 eps gnuplot> set term[inal] postscript eps enhanced gnuplot> set output "test.eps" gnuplot> set key left top gnuplot> set size 0.5, 0.5 gnuplot> set xrange [0:4] gnuplot> set yrange [0:4] ------------------- gnuplot> plot 0.2536*x+1.1717 title "lesq fit" w lines linestyle 1,\ "test.dat" u 1:2:3 t "data" w yerrorbars linestyle 2 gnuplot>unset term # windows では set terminal windows gunplot>unset output # windows?では、set outputでよい。なぜか。 -------- latex文書--------------------------------------------------- \documentclass{article} \usepackage[dviout]{graphicx} \begin{document} # \maketitle \begin{figure}[htbp] \begin{center} # \resizebox{120mm}{!}{\includegraphics[scale=0.5]{test.ps}} \includegraphics[width=9cm]{test.ps} \caption{This is a sample figure.} \label{test} \end{center} \end{figure} \end{document} (11)欄の数値を計算してとりこむ p 'force.dat' u (3*$2):(sin($3+$1)) (12)multi-plot 複数のグラフを1枚に set multiplot set size 1,0.5 set origin 0.0,0.5; p sin(x); set origin 0.0,0.0 ; p cos(x) unset multiplot 今までの設定をキャンセルするには? reset ただし、terminalとoutputはデフォルト値に戻されない。 (13)hard-copy(plotting on paper) # File name: save.plt - save a Gnuplot plot as a PostScript file # to save the current plot as a postscript file issue the commands: # gnuplot> load 'saveplot' # gnuplot> !mv my-plot.ps another-file.ps set size 1.0, 0.6 set terminal postscript portrait enhanced mono dashed lw 1 "Helvetica" 14 set output "my-plot.ps" replot set terminal x11 set size 1,1 # set terminal postscript {<mode>} {enhanced | noenhanced} # {color | colour | monochrome} # {blacktext | colortext | colourtext} # {solid | dashed} {dashlength | dl <DL>} # {linewidth | lw <LW>} # {<duplexing>} # {"<fontname>"} {<fontsize>} # set terminal gif {transparent} {interlace} # {tiny | small | medium | large | giant} # {size <x>,<y>} # {<color0> <color1> <color2> ...} # set terminal png # {{no}transparent} {{no}interlace} # {tiny | small | medium | large | giant} # {font <face> {<pointsize>}} # {size <x>,<y>} {{no}crop} # {{no}enhanced} # {<color0> <color1> <color2> ...} gnuplot> load 'save.plt' gnuplot> !mv my-plot.ps force.ps gnuplot> !lpr force.ps (14)printing two figures on one page -------cat2(executable)------- chmod +x cat2 # cat2: Shell script for putting two Gnuplot plots on one page echo %! > g.ps echo gsave >> g.ps echo 0 400 translate >> g.ps # for Gnuplot plots cat $1 | sed -e "s/showpage//" >> g.ps echo grestore >> g.ps echo gsave >> g.ps echo 0 090 translate >> g.ps # for Gnuplot plots cat $2 >> g.ps lpr -Phudsonlp1 g.ps plot1.ps とplot2.psを1枚に ==> cat2 plot1.ps plot2.ps ------------------------------------------------------------------------------- **例 1.関数プロット p sin(x),cos(x) : 2つの関数をplot 2.データプロット p 'data.dat' w e, 0.25*x+9.0 :エラーバー表示+直線 p '' u 1:($2*$3) : 1:(cos($2)*$3) (cos($1)):((cos($2)*$3) f(x,a,b)=a*x*tanh(b*x) p '' u 1:(f(x, p 'data.dat' w[ith] l[ines] : 線を引く p 'data.dat' t 'データプロット' w p :点でプロット。タイトル p 'data1.dat' t '○○' w p, 'data2.dat' t '××' w lp : 2系列をプロット p 'data.dat' u[sing] 1:2 w lp : 1列目と2列目のデータを使う p [100:300] 'data.dat' : x軸の領域設定 p [100:300] [*:0] 'data.dat' : x軸の領域、y軸の上限を設定。*はautoscale p [-2*pi:2*pi] cos(x) p [] [-2:2] cos(x) 3.グラフの設置 set <-> unset set xr[ange] [aa:bb] set yr[ange] [aa:bb] set grid set xtics 1.1,0.1,1.3 : x軸の目盛りを1.1から1.3まで0.1刻みに set xtics (1.1,"PI/2" pi/2, 1.3) set logscale x(y) : X軸(y軸)をログスケールに set xlabel 'X-Axis' set ylabel 'Y-Axis' set nozreo : x軸とy軸のゼロのところの点線を引かない。 set autoscale x : x軸の範囲を自動に。 show all show title 4.データの空白行の扱い  ・空白行が1行の場合 連結して描画しない。  ・空白行が2行の場合 index オプションにより、異なるデータ列として扱う。   例 p 'sep.dat' index 0 t 'index 0' w p, '' index 1 t 'index 1' w l 5.描画のdefault設定  ・データ描画を点から線にする set data style lines  ・関数の描画を線にする set style function lines   6.線 (1)line option ・pt,pointtype :形(丸、四角) ・ps,pointsize :大きさ ・lt,linetype :カラー、白黒 ・lw,linewidth :太さ (2)線種の手動設定(白黒印刷時) set linestyle 1 lt 1 lw 1.0 set linestyle 2 lt 1 lw 2.0 p 'data.dat' u 1:2 w l linestyle 1,'' u 1:3 t 'graph2' w l 1 linestyles2 set linestyle 1 lt 1 lw 1.0 pt 2 ps 5.0 set linestyle 2 lt 1 lw 2.0 pt 7 ps 1.0 7.データの結び方 p 'data.dat' smooth csplines (unique,bezier) キュービックスプライン曲線(線形補間という直線、ベジェ曲線)で結ぶ。 8.エラーバー w xyerrorbars 想定のデータ構造 X Y dX dY または X Y X1 X2 Y1 Y2 p 'data.dat' u 1:2:3 w yer pt 7 (データのポイント部分を塗りつぶしの丸とする) 9.タイトルなど (1)タイトルを消す  全体のタイトルなら set title 各データなら p 'sin.dat' notitle w l (2)タイトルの位置 set key bottom グラフの下 set key left 左へ set key left bottom(top) 左下(上) set key 220,0.4 グラフがx軸・y軸座標の単位で(220,0.4)に位置させる 10.ラベル (1)軸 set xlabel 'X-label' set xlabel ラベルを消す  set xlabel "{/=30 Temperatrue (K)}" 30ポイント  set ylabel "{/=30 REsistivity ({/Symbol mW} cm)}" 30pts, ギリシア文字 マイクロ、モー  set ylabel "{/=30 {/Symbol-Oblique r}_{/Arial-Italic c} ({/Symbol mW}cm)]" ギリシア文字など30ポイント (2)文字列 set label '(0,0), center-just.' at -7,0.8 グラフ座標で(-7,0.8)の位置に左寄せで                 at -7,0.8 center(right) 中央寄せ(右寄せ) set arrow form -7,0.8 to 0,0 lt 2 lw 2 set label 'label' at X,Y font 'Helvetica,24' 文字列のフォントを指定 set nolabel, set noarrow 全体を消す show label, show arrow で番号を確認し、特定のものだけを消すことができる。 11.グラフの大きさ set size 2 x軸、y軸を2倍にする set size 1,3 y軸のスケールをx軸の3倍に(縦に拡大) set size square 4 正方形のまま4倍に set size ratio 2 y軸をx軸に対して2倍に拡大 set size ratio -1 x軸とy軸の単位を揃える。地図上でのデータの表示など 12.軸の目盛り set xtics INCR 増分値をINCRに設定 set xtics START, INCR[, END] 目盛りの最初、増分値、(終わり) set xtics ('START' 0, 'MIDDLE' 250, 'END' 500) 目盛りの位置と表示文字の設定  set xtics pi  set format x "%.0PPi" もしくは set formatx "%.0PPi"  plot [0:4*pi] sin(x) w l 数値表示桁数の設定 set format x "%7.3f" 全体7桁、小数点以下3桁 set xtics (1.1,pi/2,1.3) rep 戻す set xtics    13.データの扱い (1)データ列 plot 'multi.dat' using ($1-$3) w l p 'multi.dat' u 1:(valid(2) ? $2 : 1/0) 無効なデータを無視する (2)特殊なデータ列 $0 データ行ごとに増加し、連続空白2行で0にリセット $-1 空行ごとに増加し、連続空白2行で0にリセット $-2 連続空白2行ごとに増加 データ形式に,が使われている場合 p 'ugly.dat' using 1:2 "%l%f*[, ]%lf" はじめの値を1列目、続くカンマもしくはスペースをすべて無視し、次の実数値を2列目とする。 call の場合、$1がパラメータと解釈されるので、colunmn(n)で第n列目を指定する。 14.その他 print pi # 変数の表示 myfunc(t) = sin(t/T) p [t=-2*pi:2:pi] T=1,myfunc(t) t 'T=1' w l, T=2,myfunc(t) t 'T=2' w l #(関数の実体は定義時ではなく、実行時に評価される) set samples # 1000 関数プロットの点の数を設定する 15.3次元 splot [-5:5][-5:5] sin(sqrt(x**2+y**2)) set hidden3d 隠線処理 <-> set nohidden3d set contour base 等高線をxy平面に <-> set nocontour set isosamples 30 解像度を30に (default 10) 16.postscript enhanced a~{b} 上付き a_{b} 下付き a`^{b}_{c} 上下に付く {/Symbol G} ギリシャ文字ガンマの大文字 {/Symbol g} ギリシャ文字ガンマの小文字 対数プロットの目盛りを1,10,100から10^0,10^1,10^2のべき乗に変更 set terminal postscript enhanced set logscale y set format y "10^{%L}" set key spacing 1.4 p 'data.dat' u 1:2,t '{/Symbol G}_{a}','' u 1:3 t '{/Symbol r}^{b}' set terminal postscript enchanced 'Times-Roman' 14 #(Helvetica,Times-Roman,Courierなど、defaultはHelvetica 14) set t '{/Times-Roman=40 G} {/Courier=40 G} {/Helvetica=40} {/Symbol=40 G}' set t '{/Times-Roman*2.0 G} {/Courier*2.0 G} {/Helvetica*2.0 G} {/Symbol*2.0 G}' # フォントサイズを2倍に設定 set t '{/Helvetica e}^{- {/Courier i} {/Symbol g}^2}' (関連リンク) [[GNUPLOT ポータル>>http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/index-gnuplot.html]] [[Gnuplotの第一歩>>http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/gnuplot-intro/index.html]] [[グラフは Gnuplot にお任せ>>http://ayapin.film.s.dendai.ac.jp/~matuda/Gnuplot/]] [[GNUPLOT るさんちまん>>http://mibai.tec.u-ryukyu.ac.jp/~oshiro/Doc/gnuplot_primer/]] [[Gnuplot の点点 (Postscript出力)>>http://hosho.ees.hokudai.ac.jp/~kubo/memo/gnuplot-points.html]] [[Gnuplot - Scientific Plotting>>http://www.usf.uni-osnabrueck.de/~breiter/tools/gnuplot/index.en.html]] [[gnuplot のページ (Takeno Lab)>>http://takeno.iee.niit.ac.jp/~foo/gp-jman/gp-jman.html]] [[gnuplot入門(桂田祐史)>>http://www.math.meiji.ac.jp/~mk/labo/howto/intro-gnuplot/]] 2008.7.23 [[GNUPLOT FAQ>>http://t16web.lanl.gov/Kawano/gnuplot/index.html]] 2004/8/30 [[Gnuplot入門(半場滋)>>http://dsl4.eee.u-ryukyu.ac.jp/DOCS/gnuplot/index.html]] 2007/8/31 [[GNUPLOT FAQ>>http://folk.uio.no/steikr/doc/gnuplot/Kawano/index.html]] 2003/9/15 [[gnuplot入門(岡山大学情報工学科)>>http://www.suri.it.okayama-u.ac.jp/~niitsuma/j/lecture/gnuplot_nyuumon.html]] [[GNUPLOTの使い方>>http://nucl.sci.hokudai.ac.jp/~ohnishi/Education/compphys/LESSON/gnuplot.html]] [[Visualize your data with gnuplot(IBM)>>http://www.ibm.com/developerworks/library/l-gnuplot/]] [[GNUPLOT 4.2 - A Brief Manual and Tutorial>>http://www.duke.edu/~hpgavin/gnuplot.html]] Duke Univ [[Helping you with gnuplot>>http://www.gnuplot.info/help.html]] [[Plotting data using Gnuplot>>http://mathewpeet.org/computing/gnuplot/]] [[Gnuplot Tutorial>>http://physicspmb.ukzn.ac.za/index.php/Gnuplot_tutorial]] [[gnuplot fitting tutorial>>http://www.physics.ubc.ca/~phys209/files/gnuplot_tutorial2.pdf]] [[LATEX and the GNUPLOT Plotting Program>>http://skuld.bmsc.washington.edu/people/merritt/gnuplot/tutorial.pdf]] 1991.6 [[Plotting with Fortran 90>>http://www.phy.uct.ac.za/courses/phy400w/cp/f90tut.pdf]] [[Gnuplot-mode (for Emacs)>>http://homepage1.nifty.com/fin/soft/emacs/gnuplot-mode.html]] 2001/8/9

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。