gnuplotを使ってみた
学校の実験でgnuplotを使わざるを得なかったので,調べたことをまとめる.
著者はWindows信者であるので気を付けられたい.
準備
インストール
このページからgnuplotをダウンロード.
各自の好みに合わせてインストールする.
使用方法
cdコマンドを用いてプロットしたいデータが存在するディレクトリに移動して,起動コマンドを入力する.
$
はターミナルにおける入力要請の意.
起動コマンド:
$ gnuplot-x11
また,以下では
gnuplot> コマンド
とするところにおいて,gnuplot>
を省略し,コマンドのみ記載する.
これはコピペが楽にできるようにという粋な計らい()と著者が楽するためである.
描画範囲指定
描画範囲は,以下のコマンドで軸にそれぞれ割り振ることができる.
デフォルトでは自動で調整される.
set xrange [ 始点:終点 ]
set yrange [ 始点:終点 ]
例
set xrange [100:100000]
set yrange [-40:10]
不要になった場合は次のコマンドを用いれば,範囲指定を解除できる
unset xrange
unset yrange
対数グラフ
対数グラフを使用する場合,以下のコマンドの内必要な方のみ用いればよい.
$x$軸片対数グラフにしたい場合は,set log x
のみ用いればよい.
set log x
set log y
対数グラフから普通のグラフに戻す場合は,
unset log x
unset log y
をすればよい.
軸ラベル
軸ラベルを付けるときは,次のコマンドを用いる.
デフォルトでは軸ラベル無し.
set xlabel ""
set ylabel ""
複数軸
set y2tics nomirror
nomirrorはつけなくても構わないが,付けない場合$x$軸反転となる.
MEMO
gnuplot> set xlabel "Freqency {/Helvetica:Italic f} / Hz"
gnuplot> set ylabel "Gain: {/Helvetica 20log_{10}}|{/Helvetica:Italic V_C / V_{in}}|"
gnuplot> plot "FLG" title "Gain"
gnuplot> replot "RFLG" title "Theoretical value"
gnuplot> replot 20*log10(1/sqrt(1 + (x/1557.969513)**2)) title "Theoretical line"
gnuplot> save "LowFilterGain.plt"
gnuplot> set terminal png
gnuplot> set output "LowFilterGain.png"
gnuplot> replot
gnuplot> q
$ convert -density 1000 LowFilterGain.png LowFilterGain.jpg
set xlabel "Freqency {/Helvetica:Italic f} / Hz"
set ylabel "Gain: {/Helvetica 20log_{10}}|{/Helvetica:Italic V_C / V_{in}}| / dB"
plot "FLG" title "Gain"
replot "RFLG" title "Theoretical value"
replot 20*log10(1/sqrt(1 + (x/1557.969513)**2)) title "Theoretical line", -3 title "-3 dB", 0 linetype rgbcolor 'black' title ""
save "LowFilterGain.plt"
set terminal png
set output "LowFilterGain.png"
replot
q
set term postscript eps enhanced color
set output "LowFilterPhi.eps"
set xrange [100:100000]
set yrange [-110:0]
set log x
set xlabel "Freqency {/Helvetica:Italic f} / Hz"
set ylabel "Gain: {/Symbol:Italic f}_C / {/Symbol \260}"
plot "FLP" title "Phase angle", "RFLP" title "Theoretical value", atan((-x)/(1557.969513))*180/pi title "Theoretical line", -45 title "-45{/Symbol \260}"
save "LowFilterPhi.plt"
q
convert -density 800
LowFilterPhi.eps
LowFilterPhi.jpg
set term png
set output "LowFilterPhi.png"
set xrange [100:100000]
set yrange [-110:0]
set log x
set xlabel "Freqency {/Helvetica:Italic f} / Hz"
set ylabel "Phase: {/Symbol-Oblique:Italic f}_C / {/Symbol \260}"
plot "FLP" title "Phase angle", "RFLP" title "Theoretical value", atan((-x)/(1557.969513))*180/pi title "Theoretical line", 0 linetype rgbcolor 'black' title "", -45 title "-45{/Symbol \260}"
save "LowFilterPhi.plt"
set output "LowFilterPhi.png"
replot
q
set term png
set output "Kato_Vc.png"
set xrange [-50:600]
set yrange [-2.0:11]
set y2tics nomirror
set y2range [-6:7]
set xlabel "Time / {/symbol m}s"
set ylabel "Volts of C / V"
set y2label "Volts of src. / V"
plot "Kato_VC" axis x1y1 title "Charging", "Kato_VC" axis x1y1 smooth bezier title "", "Kato_V" with linespoints axis x1y2 title "E"
set parametric
set trange [-2:4]
replot 101,t title "Times:101"
set parametric
set trange [-50:600]
replot t,2.5 title "{/symbol t}_C:2.5"
set output "Kato_Vc.png"
replot
q
set term png
set output "Kato_VR.png"
set xrange [-50:600]
set yrange [-2.0:14]
set y2tics nomirror
set y2range [-8:8]
set xlabel "Time / {/Symbol m}s"
set ylabel "Volts of C / V"
set y2label "Volts of src. / V"
plot "Kato_VR" axis x1y1 smooth unique title "", "Kato_VR" axis x1y1 title "Discharge", "Kato_V" with linespoints axis x1y2 title "E"
set parametric
set trange [-2:4]
replot 101,t title "Times:101"
set parametric
set trange [-50:600]
replot t,1.5 title "{/symbol t}_R:1.5"
set output "Kato_VR.png"
replot
q
set term png
set xrange [-2:1]
set yrange [0:3.5]
set xlabel "{/Times:Italic V} / V"
set ylabel "{/Times:Italic I} / mA"
set output "2_1.png"
plot "I-V" title "data" pt 2, 35.905383360522*x + -20.8509461663948 title "", "intersection" pt 3 title "(0.581, 0)"
q