Links
contents
Windowsであればコンパイル済み実行ファイルを使う。 Linuxであればパッケージ管理ソフトを使うのが一番楽。 MacであればMac portが便利。 それ以外はソースからのコンパイル。
Download a source file you want, e.g. "gnuplot-4.4.3.tar.gz", then make:
tar zxvf gnuplot-4.4.3.tar.gz cd gnuplot-4.4.3 ./configure --prefix=/home/username/local make make check make install
export CVSROOT=:pserver:anonymous@gnuplot.cvs.sourceforge.net:/cvsroot/gnuplot cvs login cvs -z3 checkout gnuplot
Note: hit Enter when asked for a password.
You can become root: install gnuplot to /usr/local (thus the executable will be /usr/local/bin/gnuplot, etc.):
./prepare
# Run configure, with any option(s) you like:
./configure --with-readline=gnu
or
./configure
# Now make:
make
# Now "make install", or "make install-strip" (no debugging symbols)
make install-strip
「*.gp」ファイルを開ける際に、自動的にgnuplot-modeに移行。
;; to use gnuplot-mode
(autoload 'gnuplot-mode "gnuplot"
"gnuplot major mode" t)
(autoload 'gnuplot-make-buffer "gnuplot"
"open a buffer in gnuplot mode" t)
(setq auto-mode-alist
(append '(("\\.gp$" . gnuplot-mode))
auto-mode-alist))
(global-set-key [(f9)] 'gnuplot-make-buffer)
Members/chinone/覚書/Emacs/gnuplot_mode
「.gnuplot」という名前のテキストファイルをホームディレクトリ作成:
set terminal x11
reset clear
set term post enh eps color solid
plot sin(x) lw 4
plot sin(x) lc rgb "red"
show colornames
There are 112 predefined color names:
set term post enh eps color solid 18 set out "hoge.eps" replot set out set term x11
set term post eps enh 18 set out "hoge.eps" replot set out set term x11
gridを描く:
set grid
描くgridを指定:
set grid xtics mxtics ytics mytics
set m{x|y}tics 10
set {x|y}tics 10,20,30,40
set {x|y}tics ("label1"10,"label2"100,"label3"1000)
set ytitle "hoge\nhuga"
二重引用符で囲まれた場合のみ有効。一重引用符だと不可。
set format y "10^{%L}"
gnuplotの数値の表示のフォーマットは, デフォルト では"%g". 対数グラフを描くとき, グラフの数値が適当な大きさ(0.0001 以上,100000以下)に入っていれば0.01, 1000等の"F"フォーマットの数値で表 示されが, その範囲を越えると1e-05, 1e+06の様に"E"フォーマットに切り替わる。
| f | 小数点表示 | %6.3f | 6.00 |
| e,E | 指数表示 | %11.4e | 5.0000e+01 |
| x,X | 16進数表示 | %x | fffffffb |
| o,O | 8進数表示 | %o | 37777766 |
y軸と軸名が離れすぎるため、移動させる
set ylabel"Y-Axis" 2,0
set key box
set key width 10
指定する数字は、「文字列に付け加える」文字数。
環境: gnuplot 4.0 patchlevel 0, Debian GNU/Linux Sarge
"left"を指定しているにも拘らず、凡例の幅(文字列の幅)が広すぎて、 文字が左端から離れてしまっている(空白が挿入されている)。この結果グリッドも隠されてしまっている。
その結果"Box"の幅もおかしい。
set key width -( (ギリシア文字の数) x 10 )中括弧'{','}'があるならその数も引く必要がある。 TeXの癖でまとめる際に中括弧を使ってしまうが、Postscript出力されるときには無意味?同様に、powerを書くときに使う'^'も一文字だが、実際は幅が違う。
set key width -17
set key spacing 1.5
set key hoge
| hoge | place |
| left | 左側 |
| right | 右側 |
| top | 上側 |
| bottom | 下側 |
| outside | 図の右側の外 |
| below | 図の下側の外 |
| center | 中心;どちらにも指定可 |
幾つかのものは組み合わせて指定可能。 凡例を表示する座標を直接指定することも可能。
set key x,y
set label 1 "a=%f", a at x,y, set label 2 "b=%f", b at x,y,,.のように指定する。
set label 1 "a = %10.8f", a at 1.1,2
set label 2 "b = %10.8f", b at 1.1,1
set label 3 "reduced-{/Symbol c}^2 = %10.8f", chi_sq at 1.1,0
plotを作成する際に計算される値を、図中に書き込みたくなる場合がある。 その場合は「sprintf」を使う:
value = f_sky(N1, t_yr)*1e+2
set label sprintf("%.2f", value) at 1.2,value front
ここで「fsky」は事前に定義した関数で、N1,t_yrも値が代入してある。
set style fill transparent solid 0.5 noborder
p'power_tensCls.dat' u 1:(sqrt($3)):(sqrt($8)) w filledcu lc rgb "red" t'Power Law'
''set {x|y}zeroaxis
set xzeroaxis lt -1 set yzeroaxis
#[RQ_0000,Demod]
0 -127923 55630 6140 160361
1 -122188 54358 10729 161043
2 -128985 41169 9877 151982
3 -382 7398 -8453 2789
#[RQ_0001,Demod]
0 589 9455 -2350 6288
1 9704 2585 5484 -1966
2 -2973 -4166 2578 -198
3 -12 2755 4732 -148
#[RQ_0002,Demod]
0 514 -10542 10718 3925
1 -168 -1631 3933 653
2 -71 107 -609 971
3 -4204 -3035 1312 -1051
上のような改行(二回)で区切られたデータをプロットする場合indexを使う:
p"data.dat" index 0 u 1:2 w l,\ "" index 1 u 1:2 w l,\ "" index 2 u 1:2 w l
indexはC言語のように0から始まる。 indexの指定には例えば上記のデータの場合
p"data.dat" index '[RQ_0000,Demod]' u 1:2 w l ,\ "" index '[RQ_0001,Demod]' u 1:2 w l ,\ "" index '[RQ_0002,Demod]' u 1:2 w l
のような指定も可能である。
「set multiplot layout」を使う。 書きたいグラフの個数分だけrow,colを並べる。
set multiplot layout 2,2 title""
右左、上下の間隔はmarginで適当に変化させる。
reset
clear
################################################
set term post enh eps color solid 12
set out "p_cl_posterior_histogram_l02-10_c10000_n10.eps"
################################################
# set top and bottom margins to 0
# so that thereis no space between plots
set bmargin 3
set tmargin 2
# set left right margins to same value
# so that there some space to plot y ranges
set lmargin 8 # 3
set rmargin 4 # 3
# set xrange
set xrange[0:3000]
set xlabel"l(l+1)C_l/(2{/Symbol p}) [{/Symbol m}K^2]"
set xtics 500
# set multiplot layout
set multiplot layout 2,2 title"MCMC chain, posterior distribution" # row,col
###############################################################
# set 1st plot
p'cl_posterior_histogram_l02-50_c10000_n10.dat' index 0 u 2:3 w fsteps t"l=2"
# set 2nd plot
p'cl_posterior_histogram_l02-50_c10000_n10.dat' index 1 u 2:3 w fsteps t"l=3"
# set 3rd plot
p'cl_posterior_histogram_l02-50_c10000_n10.dat' index 3 u 2:3 w fsteps t"l=5"
# set 4th plot
p'cl_posterior_histogram_l02-50_c10000_n10.dat' index 8 u 2:3 w fsteps t"l=10"
unset multiplot
################################################
set out
set term x11
################################################
「set multiplot layout」を使う。 書きたいグラフ+1個のrowを宣言する:
set multiplot layout 5,1 title""
こうすることで、一番下の余ったrowにx軸のtics, labelを書く。 当然上の空白と下の空白がいびつになるので、 titleやlabelに改行を入れて、空白が等しくなるように調節する。
それでも空白自体は残るので、 もっと綺麗にしたいのならば、 他のツールでいじるしかない。
reset
clear
##########################################
set term post enh eps color solid 12
set out "p_s_c10000_n10.eps"
##########################################
# set top and bottom margins to 0
# so that thereis no space between plots
set bmargin 0
set tmargin 0
# set left right margins to same value
# so that there some space to plot y ranges
set lmargin 10 # 3
set rmargin 4 # 3
# set xrange
set xrange[0:10000]
set xtics 1000
# set multiplot layout
set multiplot layout 5,1 title"\n\n\nMCMC chain, CMB [{/Symbol m}K]\n" # row,col
# set xlabel none between plots
set format x""
set xlabel""
###############################################################
# set 1st(top) plot
set yrange[45:95]
set ylabel"p=17300"
true = 61.7866
p'mcmc_s_d0.9_c10100_p17300_n10.dat' w l t"{/Symbol s}_s=0.9",\
'mcmc_s_d1_c10100_p17300_n10.dat' w l t"{/Symbol s}_s=1.0",\
'mcmc_s_d2_c10100_p17300_n10.dat' w l t"{/Symbol s}_s=2.0",\
true notitle
# set 2nd plot
set yrange[60:140]
set ylabel"p=17301"
true = 98.9004
p'mcmc_s_d0.9_c10100_p17301_n10.dat' w l notitle,\
'mcmc_s_d1_c10100_p17301_n10.dat' w l notitle,\
'mcmc_s_d2_c10100_p17301_n10.dat' w l notitle,\
true notitle
# set 3rd plot
set yrange[-210:-150]
set ylabel"p=28170"
true = -176.081
p'mcmc_s_d0.9_c10100_p28270_n10.dat' w l notitle,\
'mcmc_s_d1_c10100_p28270_n10.dat' w l notitle,\
'mcmc_s_d2_c10100_p28270_n10.dat' w l notitle,\
true notitle
# set 4th(bottom) plot
set format x"%g" # reset xformat
set xlabel "chain" # set xlabel
#
set yrange[-160:-110]
set ylabel"p=28171"
true = -130.755
p'mcmc_s_d0.9_c10100_p28271_n10.dat' w l notitle,\
'mcmc_s_d1_c10100_p28271_n10.dat' w l notitle,\
'mcmc_s_d2_c10100_p28271_n10.dat' w l notitle,\
true notitle
###############################################################
# unset multiplot
unset multiplot
##########################################
set out
set term x11
##########################################
reset
clear
###################################
set term post enh eps color solid
set out 'sigma_theta.eps'
###################################
set xrange[0:180]
set xtics 10
set lmargin 10
set rmargin 2
set multiplot
######################################################################################
set size 1,0.4
set origin 0,0
set bmargin 3
set tmargin 0
set yrange[0.5:1.5]
set ylabel'ratio'
set xlabel'Angle, {/Symbol q} [deg]'
p'sigma_WideS_N60.dat' u 1:(($4)/($2) ) t'{FWHM}_{N60}/{FWHM}_{WideS}',\
37./39. t'{FWHM}_{N60}/{FWHM}_{WideS} [M. Kawada et al.]' ,\
65./90. t'{/Symbol l}_{N60}/{/Symbol l}_{WideS} [M. Kawada et al.]'
######################################################################################
set size 1,0.6
set origin 0,0.4
set bmargin 0
set tmargin 1
set format x''
set xlabel''
set yrange[25:75]
set ylabel'FWHM [arcsec]'
p'sigma_WideS_N60.dat' u 1:(2.35*($2)*4.0) t'WideS',\
'' u 1:(2.35*($4)*4.0) t'N60',\
39 t'WideS [M. Kawada et al.]' ,\
37 t'N60 [M. Kawada et al.]'
unset multiplot
###################
set out
set term x11
###################
set origin, set size等を使って調節する。
reset
clear
######################################
#set term post enh eps color solid 12
#set out "histogram_KKaQVW.eps"
######################################
set grid
set yrange[:2*1e+4]
set ylabel'number of pixel'
set multiplot
set size 0.5, 1
set origin 0, 0
set lmargin 10
set rmargin 0
set logscale y
set xrange[-200:200]
set xlabel'{/Symbol m}K'
p'030_h.dat' t'' ,\
'K_h.dat' t'' ,\
'Ka_h.dat' t'' ,\
'Q_h.dat' t'' ,\
'V_h.dat' t'' ,\
'W_h.dat' t''
set size 0.5, 1
set origin 0.5, 0
set format y''
set lmargin 0
set rmargin 2
set logscale
set xrange[200:50000]
set xlabel'{/Symbol m}K, log scale'
unset ylabel
p'030_h.dat' t'30GHz' ,\
'K_h.dat' t'K, 23GHz' ,\
'Ka_h.dat' t'Ka, 33GHz' ,\
'Q_h.dat' t'Q, 41GHz' ,\
'V_h.dat' t'V, 61GHz' ,\
'W_h.dat' t'W, 94GHz'
unset multiplot
###############################
#set out
#set term x11
arrowを使う。矢印がいらないので消す。
set arrow nohead from x_from,y_from to x_to,y_to lw 1
dgrid3dは非格子状データ(
Dec2007-02-12_18-20-00.dat)から格子状データへの写像を行い、3Dグラフを描く。
非格子状データ(
sb.dat)とは違い(空行一行で区切られている)、
3.42500 -44.97917 0.995111752789 5.45833 -44.97500 1.015607330177 55.37083 -43.00000 0.705641735150 52.84167 -42.99583 0.998811481967 ... ... ...
のようなデータのことを言う。
デフォルトではdgrid3dは無効になっている。 有効になると、ファイル から読み込まれる3Dデータは「散在した」データ (非格子状データ) であると見なされるようになる。
set dgrid3d {<row_size>} {,{<col_size>} {,<norm>}}
unset dgrid3d
show dgrid3d
格子はx方向(行)とy方向(列)に等間隔。 zの値は散在するデータのzの値の重み付きの平均として計算される。
3番目のパラメータであるノルム(norm)は、重み付けを制御するもので、 各点は格子点からの距離のnorm乗の逆数で重み付けされる。 実際には、dx, dyを各データ点と格子点との差の成分であるとすると、 重みは
dx^norm + dy^norm
で与えられる2のべきのノルム、特に 4, 8, 16 に関しては、 その重みの計算はユークリッド距離を使うことで
(dx^2+dy^2)^norm/2
のように最適化されている。
格子点に近いデータ点程それはその格子点により大きい影響を与え、ノルムの値が大きい程格子点から離れた点の影響は小さくなる。
zの値は全てのデータ点の重み付けとして求められる。 隣接するデータ点を補間している訳ではない。
ある場合では、
を作ってしまう。
zの値は0.4で一様
zの値が全体的に、明らかに0.4より小さくなっている。
raw dataにほぼ一致した等高線が描けている。
全体的に一様だが、ところどころに「とび」の箇所があることがcontourで分かる。
2 211.0000 3 1041.0000 4 731.0000 5 1521.0000 6 661.0000 7 1331.0000 8 671.0000 ・・・・・・・・・
の様なデータを、Contour上にプロットしたい。 プロットの濃淡ではなく「線」を書きたい。
set pm3d map
set pm3d explicit
#
sp'wmap_comb_tt_powspec_3yr_v2.txt' u ($1):($2):(1) w l lt 2 t"WMAP" ,\
'wmap_lcdm_wmap_scalCls_v2p2.dat' u ($1):($2):(1) w l lt 3 t"{/Symbol L}CDM"
これだけでは意味が無い。
これはpm3d組み合わせて意味がある。
0 91 0.0000000 0 92 0.0000000 0 93 0.0000000 0 94 0.0000000 0 95 0.0000000 0 96 0.0000000 0 97 0.0000000 0 98 0.0000000 0 99 0.0000000 0 100 0.0000000 0 101 0.0000000 0 102 0.0000000 0 103 0.0000000 0 104 0.0000000 0 105 0.0000000 0 106 0.0000000 0 107 0.0000000 0 108 0.0000000 0 109 0.0000000 0 110 0.0000000 1 0 0.5855275 1 1 0.1936445 1 2 0.0132028 1 3 0.0003827 . . .
reset
clear
set pm3d map
set isosample 100000
set title"Spherical Bessel; {j_l(k{/Symbol h})}^2"
set xlabel"k{/Symbol h}"
set ylabel"multipole; l"
set xrange[50:110]
set yrange[50:110]
set xtics 5
set ytics 5
sp "sb.dat" w pm3d notitle
set term post enh eps color solid 21
set out "SphericalBesselJ_3d_large.eps"
replot
set out
set term x11
描画される各 pm3d 四辺形には一つの灰色/カラー値が対応します (4 頂点間 で滑らかなカラー変化は起こりません)。
その値は、`corners2color <option>` に従って周囲の角の z 座標から計算されます。
<option> は 'mean' (デフォ ルト)、'geomean', 'median' で、曲面のカラーの滑らかさに幾つかの種類を 与えます。
&color(red){これらは鋭敏な、あるいは急激なピーク値を持つようなピクセルイメージや色地図を作るときには必要ありません。
そのような場合には、むしろ オプション 'c1', 'c2', 'c3', 'c4' を使って、
四辺形の色の割当にただ一つ の角の z 座標を使うようにすればいいでしょう。};
どの角が 'c1' に対応する のかを知るためには何回か実験してみる必要があるでしょう。
その向きは描画 の方向に依存しています。
pm3d アルゴリズムは、カラー曲面を入力データ点 の範囲の外には描かないので、
オプション 'c<j>' は、格子の 2 つのへりに 沿ったピクセルが、
どの四辺形の色にも寄与しない、という結果をもたらしま す。例えば、
pm3d アルゴリズムを 4x4 のデータ点の格子に適用するスクリプ ト `demo/pm3d.dem` (是非見てください) では、
(4-1)x(4-1)=9 色しかない長 方形が生成されます。
文字列中にギリシア文字を使うにはterminalをenhanced postscriptにする必要がある。
set term post enh
ギリシア文字は文字列中で
{/Symbol a}
の様に使う。以下にアルファベットとギリシア文字の対応を挙げる。
| alphabet(capital) | symbol | alphabet(small) | symbol | |
| A | Α | a | α | |
| B | Β | b | β | |
| C | Χ | c | χ | |
| D | Δ | d | δ | |
| E | Ε | e | ε | |
| F | Φ | f | φ | |
| G | Γ | g | γ | |
| H | Η | h | η | |
| I | Ι | i | ι | |
| J | j | |||
| K | Κ | k | κ | |
| L | Λ | l | λ | |
| M | Μ | m | μ | |
| N | Ν | n | ν | |
| O | Ο | o | ο | |
| P | Π | p | π | |
| Q | Θ | q | θ | |
| R | Ρ | r | ρ | |
| S | Σ | s | σ | |
| T | Τ | t | τ | |
| U | Υ | u | υ | |
| V | v | |||
| W | Ω | w | ω | |
| X | Ξ | x | ξ | |
| Y | Ψ | y | ψ | |
| Z | Ζ | z | ζ |
set size square
eps2eps input.eps output.eps
y軸がX軸のX倍、で指定する。
set size ratio X
set size ratio -X
every X
every I:J:K:L:M:N
三項演算子を使う:
plot x>0 ? exp(-x) : exp(x)
複雑なplotを作成していると、一つの「.gp」ファイルだと長くなりすぎてしまい、煩わしい思いをすることになる。 そこで部分部分を別々の「.gp」ファイルにし、mainファイル内で「load (l)」を使うことで、記述を簡潔にすることが出来る。
reset clear set term x11 ymax=1e+2 ymin=2.5e-7 l"conf_cl.gp" l"conf_planck.gp" l"conf_core.gp" l"conf_litebird.gp" l"conf_quiet.gp" l"conf_polarbeark.gp" l"conf_fg.gp" l"conf_legend.gp" fsky_satellite=0.73 fsky_ground=2.424/100.0 eff_L2=fsky_satellite eff_LEO=0.256 p'power_tensCls.dat' u 1:(($4)):(($9)) w filledcu fs solid 0.7 lc rgb "orange" t'Power Law' ,\ 'chaotic_p1_tensCls.dat' u 1:(($4)):(($9)) w filledcu fs solid 0.7 lc rgb "green" t'Chaotic p=1' ,\ 'ssb_tensCls.dat' u 1:(($4)):(($9)) w filledcu lc rgb "purple" t'SSB (N_e=47-62)' ,\ 'chaotic_p0.1_tensCls.dat'u 1:(($4)):(($9)) w filledcu fs solid 0.7 lc rgb "yellow" t'Chaotic p=0.1' ,\ 'lensing_lensedCls.dat' u 1:(($4)) w l lt 0 lw 4 notitle ,\ 'lensing_lensedCls.dat' u 1:(($3)) w l lt -1 lw 1 notitle ,\ 'r0.001_tenscls.dat' u 1:(($4)) w l lt -1 notitle ,\ cv(x,fsky_satellite)*Nl_planck(x) lc rgb "blue" lw 3 t'PLANCK' ,\ cv(x,fsky_ground)*Nl_qband_quiet1(x) lc rgb "green" lw 3 t'QUIET Q-band' ,\ cv(x,fsky_ground)*Nl_wband_quiet1(x) lc rgb "magenta" lw 3 t'QUIET W-band' ,\ cv(x,fsky_ground)*Nl_PBI(x) lc rgb "brown" lw 3 t'POLARBEAR' ,\ cv(x,fsky_ground)*Nl_wband_quiet2(x) lc rgb "cyan" lw 3 t'QUIET 2' ,\ cv(x,fsky_satellite)*Nl_litebird(x) lc rgb "red" lw 4 t'LiteBIRD' ,\ foreground(x) lc rgb "dark-cyan" lw 2 notitle ,\ foreground(x)*1e-4 lc rgb "dark-cyan" lw 1 notitle set term post enh eps color solid 12 set out 'Cl_test.eps' replot set out set term x11
ここで「l"conf_hoge.gp"」では複雑な関数の定義等がなされている(「plot""」等のコマンドは一切無し)。 私の環境では、1ファイルにベタ書きするよりも、実行速度も改善した。