今日も勉強です。ここに私が調理した小さな例があります。
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char **argv) {
ofstream file("data.dat");
file << "#x y" << endl;
for(int i=0; i<10; i++){
file << i << ' ' << i*i << endl;
}
file.close();
return 0;
}
それを plot.cpp として保存し、g++ でコンパイルします。
g++ plot.cpp -o plot
プログラムを実行して .dat ファイルを作成します。
./plot
次の gnuplot スクリプトを plot.plt として保存します。
set terminal svg enhanced size 1000 1000 fname "Times" fsize 36
set output "plot.svg"
set title "A simple plot of x^2 vs. x"
set xlabel "x"
set ylabel "y"
plot "./data.dat" using 1:2 title ""
gnuplot でスクリプトを実行して、.svg ファイルを生成します。
gnuplot plot.plt
結果のプロットは plot.svg になります。出力を指定する最初の数行を省略すると、ウィンドウにレンダリングされます。楽しむ!