2011年6月21日

[心得]gnuplot in action -- chapter 10

這一張主要介紹三樣內容
  • multiplot,也就是把多張圖彙集成一張的方式
  • 其他的繪圖style,如polar graph跟field graph
  • Curve Fitting
t(x,n) = cos(n*acos(x)) # Define some function
set xrange [-1:1]
set yrange [-1:1]
set multiplot title "Chebyshev Polynomials" layout 3,2
plot t(x,1)
plot t(x,2)
plot t(x,3)
plot t(x,4)
plot t(x,5)
plot t(x,6)
unset multiplot

multiplot那行指令一輸入,就可以看到圖形的輸出,接著每個plot會被輸出到一個sub-graph內,multiplot指令的格式如下
set multiplot [ title "{str:title}" ]
 [ layout {int:rows},{int:cols}
[ rowsfirst | columnsfirst ]
[ downwards | upwards ]
[ scale {flt:xfactor}[,{flt:yfactor}] ]
[ offset {flt:xoff}[,{flt:yoff}] ] ]
我認為比較重要的有title,標題,layout 3,2,表示幾列(3)幾行(2)的格子,讓你用來裝sub-graph,接著是rowfirst or column first,rowfirst表示先把每一列的格子填滿在開始填入下一列,column first表示先把第一行填滿在下一行

書中也給一個mutiplot的應用,這裡要注意的是,multiplot很多參數是沿用的,所以如果需要的話你必須reset

lgn( x, s ) = exp(-0.5*(log(x)/s)**2)/(x*s*sqrt(2*pi))
clgn( x, s ) = 0.5*(1+erf(log(x)/(s*sqrt(2))))
set multiplot layout 2,1
set bmargin 0  #取消掉bmargin的部分,讓他可以跟下個圖形貼在一起
set format x "" #當然就要把x軸的label拿掉
set ytics 0.2,0.2
set key bottom
plot [0:2.5][0:1] clgn(x,0.5) t "s=0.5", clgn(x,1) t "s=1.0", clgn(x,5) t "s=5.0"
set bmargin #接著把bmargin的部分加回來,好放置xlabel
set tmargin 0 #換成把tmargin移除,讓兩個徒可以貼再一起
set format x "%g" 一樣重新設定回來
set ytics 0,0.2,0.8
set key top
plot [0:2.5][0:1] lgn(x,0.5) t "s=0.5", lgn(x,1) t "s=1.0", lgn(x,5) t "s=5.0"
unset multiplot


在數學上,有些圖形不是單一個方程式形成,也不是兩個方程式相加,而是兩個方程式的y values聯集起來(數學家搞這個有的沒得做啥@@a),gnuplot也對方程式(只對方程式有用),提供了這樣的一個方法叫做set parametric,把一個變數當成自變數,然後其他方程式產生的y都視為同一群的資料
set parametric
plot [0:2*pi] cos(t), sin(t)
這個鳥蛋一樣的圖形就是兩個function合起來的




如果不用parametric,他就會像是這樣

沒有留言: