set grid; set grid mytics mxtics; set mytics 5; set mxtics 5; au2fs=0.02418
fn='chsRC1Xg32N.sup'; plot fn u (au2fs*$2):3 w l, fn u (au2fs*$2):4 w l, fn u (au2fs*$2):5 w l, \
fn u (au2fs*$2):7 w l, fn u (au2fs*$2):8 w l, fn u (au2fs*$2):15 w l, \
fn u (au2fs*$2):14 w lau2fs=0.02418
if ( au2fs == 0.02418 ) { set xlabel "time (fs)" } else {
if ( au2fs == 1 ) { set xlabel "time (au)" } else {
set xlabel "time (ERROR: illegal au2fs)" } }gnuplot> ! ls
pstyle="lp" plot hogehoge @pstyle hogehoge
gnuplot> set terminal x11 position 0,0 または、 $ gnuplot -e "set terminal x11 position 0,0; hogehoge" hogescript.gp $ gnuplot -e "set terminal x11 position 0,1050;hogehoge" hogescript.gp $ gnuplot -e "set terminal qt position 0,1050;hogehoge" hogescript.gp
$ gnuplot > set datafile commentschars "#@&" > plot 'file.xvg' u 1:CN w l #CNはデータの列番号
#!/bin/bash --norc
df=' file1.dat fil2.dat file3.dat file4.dat '
nd[6]='max\_d'
nd[10]='max\_disp\_eh'
nd[8]='max\_disp\_x'
for n in 6 10 8 ; do
str=''
for f in $df; do
str="$str '$f' u 1:$n w lp, "
done
str="plot $str"
str=`echo $str | sed 's/,$//'`
echo "set title '${nd[n]}'" > .load.gp
echo $str >> .load.gp
gnuplot '.load.gp' -e "set grid; set xrange[0:100]; set logscale y; replot" -
doneset terminal qt position 10,1100; replot set terminal qt position 10,110; replot など
set parametric degree=pi/180 plot tan(t*degree),tan(t/2*degree) set trange[-180:180] h=5; set xrange[-h:h]; set yrange[-h:h]; replot plot t, t, t, 2*t #となどとすると媒介変数による複数のグラフを描ける
rcd = system( 'test -f '.'hoge.xvg'.' && echo 0 || echo 1' )
if (rcd == 0) {
set style fill solid
set boxwidth 0.8 relative
set xtics rotate by 90 right
plot 'hoge.xvg' u 1:2 w boxes title 'hoge'
}gnuplot -e "set terminal qt position 1250,500; plot sin(x); pause -1" 複数ディスプレイでも 右上が 0,0 である、たぶん。
using 1:(-$7) などができる。ここで$7はカラム番号である(ファイル内データの7番目のカラム)、 $7の符号を逆転させている。 7を変数ncで与えたい場合は using 1:(-column(nc))とする。 また、log10(), abs() などの関数も使える。
plot 'output.txt' u 1:(sqrt($4)) every w l #例
また、using 1:($7>0.0 ? $1 : $2) などの三項演算子も使える。
linuxコマンドpasteを使う。ファイル名を変数として扱うときは下の例のように文字列結合をするとよい。
f0='hoge0.dat' f1='hoge1.dat' plot "< paste ".f0." ".f1 using 3:($11/$4) title "ratio" #例
plot 'output.txt' u 1:2 every 51 w l
plot 'list.libxc_graph' using 2:1 with impulses title '# of paper in the libxc Mar 28'
plot 'list.libxc_graph' using 2:1 with boxes title '# of paper in the libxc'
(例) 縦長のグラフを横に2つ並べる set size 0.5,1.0 set multiplot set origin 0.0,0.0 ; plot sin(x) set origin 0.5,0.0 ; plot cos(x) unset multiplot
欠損データは NaN (グラフの線がここで途切れる)
無効な値は ? (set datafile missing "?" のように設定できるらしい。1/0の計算値でもよい。
グラフの線はここを飛ばして引かれるが、using 1:($2)のように()内で使うと
欠損データ扱いになって、途切れる。)
例
set style data linespoints
plot '-' title "(a)"
1 10
2 20
3 ?
4 40
5 50
e
plot '-' using 1:($2) title "(d)"
1 10
2 20
3 NaN
4 40
5 50
e
[ref] http://takeno.iee.niit.ac.jp/~foo/gp-jman/data/20190108/gnuplot-ja/index.html#missing
次のようなファイル tmp.trjがあったとする。
0.03125 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 ... 0.06250 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 ... 0.09375 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 ... ...
1列と2列、1列と9列、1列と10列、を使って3本のグラフを描く。
$ gnuplot gnuplot> plot "tmp.trj" u 1:2 w l, "tmp.trj" u 1:9 w l, "tmp.trj" u 1:10 w l
または、リモートログイン時は
(たとえば windows PC(ホスト名がhogehoge)から端末で 別のマシンにログインしており、
別のマシンで実行した gnuplotのグラフをwindows PCに表示したいとき)
$ DISPLAY=hogehoge.eit.hirosaki-u.ac.jp:0 gnuplot
もしくは、sshリモートログイン時に -Yオプションを付けていた場合などは、単に、
$ gnuplot
とする。
set key at 3.5,-5 #座標は凡例の右下の位置、に表示らしい set key right bottom #右下に表示(bottom以外に、top, centerなどあり) set key font "Arial,13" #ほかに"Times New Roman,12"なども可
clear # グラフの消去 reset # 設定の初期化(表示領域をデフォルトにもどす)
show variable #ユーザ変数の一覧 undefine fn # 変数の取消
set terminal #ターミナルの一覧を表示する(説明つき) show terminal show term #利用中のターミナルの種類を知る
set term postscript [colorなど] #変更 set term png set term x11 show output #利用中の出力先を知る set output "output.ps" #-> lprプリンタ #印刷? save "output.plt" #-> load "output.plt" できる #現在の状態を保存
Ubuntu 16.04 では 14.04のように wxt は簡単には利用できなくなった。 代わりに gnuplot-qt パッケージをインストール(gnuplot-x11 と入れ替える)して、 set term qt を使うのが良い。
gnuplotで作成したGIFアニメ→adobe premiere elementsで単に読み込む。 →右上の書き出し・配信→携帯電話・携帯プレイヤ→種類はApple TV,iPad,iPhone4の720p 29.97で良い。
Premiereの操作はAdobe Premiere elementsの操作などを参照。
# 2018/12/16
f2='demoga4b.vCFEM2.dx010dt0.0005.trj-linex'
t0 = 0.0
x0 = 5.0
px = 4.0
dt = 0.0005
maxstep = 150000
trjevery = 1000
nframe = maxstep / trjevery # number of frame data
set term qt enhanced size 1200,400 #ターミナルqtのキャンパスサイズを指定
#gifアニメを作るときは、次の2行をコメントアウトを外す。
# set term gif enhanced animate delay 20 optimize size 1200*1.5,400*1.5
# set output "temprev.gif"
do for [ frame = 0 : nframe : 1 ] {
#--------------------------------------------------------------------------------
time = t0 + frame * trjevery * dt
packetcenter = x0 + px * time
packetwidth = 2.5 + 5.0 * time
xrangemax = packetcenter + packetwidth
xrangemin = packetcenter - packetwidth
yrangemax = 1.0
yrangemin = -yrangemax
set xrange [ xrangemin : xrangemax ]
set yrange [ yrangemin : yrangemax ] #自動にするときはコメントアウトする
set grid
set title font "Arial,16"; set title "Time evolution of a gaussian wave packet"
set xlabel font "Arial,16"; set xlabel "x-axis (bohr)"
set ylabel font "Arial,16"; set ylabel "{/Symbol y}(x,t)"
set key font "Arial,16"; set pointsize 8 #凡例文字、ポイントサイズ
set tics font "Arial,12"; set format x "%5.0f"; set format y "%5.2f" #目盛文字、フォーマット
set mytics 5 #副目盛の数
set grid mytics
strtitle(frame) = sprintf("t=%5.3f au ( frame %d )", time, frame )
unset label
set label f2 font 'Arial,11' at graph 0.02, 1.03
set label strtitle(frame) font 'Arial,18' at graph 0.55, 0.70
set label "{/Symbol y}(x,t=0) =(2 {/Symbol p} w^2)^{-1/4} exp[-(x-x_0)^2/(4w^2) + i p_x(x-x_0)]" \
font 'Arial,18' at graph 0.02, 0.9
set label "where x_0=5, p_x=4, w=0.5" \
font 'Arial,14' at graph 0.03, 0.8
f2ps=1
f2pe=5
plot \
f2 u f2ps:f2pe+1 every ::0:frame::frame w l lc rgb "blue" title " Re[{/Symbol y}(x,t)]", \
f2 u f2ps:f2pe+2 every ::0:frame::frame w l lc rgb "green" title " Im[{/Symbol y}(x,t)]", \
f2 u f2ps:f2pe+0 every ::0:frame::frame w l lc rgb "red" title " |{/Symbol y}(x,t)|^2", \
#pause 0.1
#pause 0.1
if( frame == 0 ) {
pause 2.0
}
if( frame <= 10 ) {
pause 0.25
}
if( frame <= 20 ) {
pause 0.25
}
if( frame == nframe ) {
pause 2.0
}
#pause -1
#--------------------------------------------------------------------------------
}
unset output #STDOUTになる(see: show output)
print 'the end'
print 'to reread, press enter' ; pause -1 ; reread
pause -1