“Serial evaluation occurs only in parentheses
and is guaranteed to proceed in left to right order.
The value of the rightmost subexpression is returned.
(GNUPLOTのhelp operator binaryより)”
例えば、(y=$3<10 ? $3 : lasty, lasty=$3, y)
。
以下のsample.gpでは1つ前の値をlastyに取っておいて、ノイズを消すのに使っている。
データの簡単な微分に使うこともできる→
http://www.ss.scphys.kyoto-u.ac.jp/person/yonezawa/contents/program/gnuplot/diff_data1.html 。
この文章は Gist https://gist.github.com/t-nissie/623722da9fff4403ee0d に置いてある。
git clone [email protected]:623722da9fff4403ee0d.git serial_evaluation
でクローンできる。
sample.gp:
#!/usr/bin/env gnuplot # Shebang for UNIX
# See help of: encoding, terminal, ternary, operator binary, datafile, command
# epstopdf.pl: http://www.ctan.org/tex-archive/support/epstopdf
##
set encoding iso_8859_1 # for Angstrom
set terminal postscript portrait enhanced color dashed "Times-Roman" 20
set output "sample.eps"
set xlabel '{/Times-Italic x} [km]'
set ylabel '{/Times-Italic y} [\305]' # Angstrom
set ytics 1
set size 1.0, 0.4
plot 'sample.dat' using 1:2 title 'column 2' with linespoints lt 1 lw 3 ps 2,\
'sample.dat' using 1:(y=$3<10 ? $3 : lasty, lasty=$3, y) \
title 'column 3' with linespoints lt 2 lw 3 ps 2
set output # ensure to close the output file
!epstopdf.pl sample.eps
sample.dat:
# Sample data file with a
# blank record and a noise
##
0 4.1 4.8
1 3.4 4.0
2 1.9 123.4 Noise
3 1.0 2.2
4 1.1 1.0
5 1.4 0.7
6 1.5 0.8
7 2.6 0.6
8 2.8 0.5
9 2.9 0.4
10 2.7 0.2
UNIXの場合は gnuplot sample.gp
、
Windowsの場合は gnuplot.exe sample.gp
などと実行する。
実行結果は図のとおりになる。
図: sample.gpを実行して得られるEPSファイルをJPEG化したもの。
- GNUPLOTをスクリプト言語として実行して
- データファイルを読み込ませて
- EPSファイルとしてグラフをプロットした
- データに空白行があるとデータは線で結ばれない
- 「Å」を出すこともできる
- serial evaluationを使ってみた
- EPSをさらにPDFに自動的に変換した
- 3項演算子も使ってみた
- 蛇足: SlideShareの GNUPLOTをうまく使って美麗なフォノンの分散関係を描く方法