目的
gnuplot でデータをスクリプトファイルに直接書きたい.
解決方法
gnuplot-5.0
からデータを sh
などでおなじみの here document 形式でスクリプトファイルに直書きすることができるようになりました.もちろんプロンプトから入力することもできます.要素数の少ないデータならスクリプトに含めてしまうことで,プロット用スクリプトの管理が簡単になります.gnuplot のドキュメントには以下のような例が挙げられています.
sample.gp$Mydata << EOD 11 22 33 first line of data 44 55 66 second line of data # comments work just as in a data file 77 88 99 EOD stats $Mydata using 1:3 plot $Mydata using 1:3 with points, $Mydata using 1:2 with impulses
[gnuplot-5.0 document]gpdoc5
プロットだけでなく,データの統計量を計算する stats
コマンドの引数としても使うことができます.
プロットの一部にラベルを貼り付けたり,プロットの端に典型的なエラーサイズを図示したりするときに便利かなと思っています.いかに簡単なサンプルを貼付します.
heredocument.gp
$HOGEDATA << EOD
1 1
2 1
2 2
3 2
3 1
4 1
4 2
5 2
5 3
4 3
4 4
3 4
3 5
2 5
2 4
1 4
EOD
$FUGADATA << EOD
1 1 "1st"
4 1 "2nd"
4 4 "3rd"
1 4 "4th"
EOD
set xr [0:6]
set yr [0:6]
plot $HOGEDATA u 1:2 w l, \
$FUGADATA u 1:2 w p, \
$FUGADATA u 1:2:3 w labels offset 1.7,0.5 notitle
###
参考資料
- [gnuplot home page][gnuplot]
- [GNUPLOT Version 5.0 Release Notes][gp5.0]
- [gnuplot 5.0 document]gpdoc5
[gnuplot]: http://www.gnuplot.info/
[gp5.0]: http://www.gnuplot.info/ReleaseNotes_5_0.html
[gpdoc5]: http://www.gnuplot.info/docs_5.0/gnuplot.pdf