
Contents
- 実行環境
- バッチモード(グラフ出力後、psql
に戻る) - 対話モード(gnuplot
のシェルに入り、作業後に psql に戻る) ※ 追記 #1(8 月 6 日)、#2(8 月 7 日、実行ユーザの件)
実行環境
••
•
•
今回、psql
バッチモード(グラフ出力後、psql に戻る)
gnuplot基本の流れは ↓ こんな感じ。最初に出力内容を「データのみ、整形なし、タブ区切り」にして
-- set output format # \t on \\\pset format unaligned \\\f '\t' # select x * cos(x * pi()), x * sin(x * pi()) from generate_series(0, 7.0, 0.01) as x \g | gnuplot -e "set terminal dumb; plot '<cat'"

gnuplot
一つのポイントは、plot
クエリ結果を確認してからグラフ描画したければ ↓ セミコロンと改行で
# select ... ;-- execute SQL ... ... (query result) ... # \g | gnuplot ... (same as above)
メタコマンド
-- set user's meta command as a variable # \set gpp '\\g | gnuplot -e "set terminal dumb; plot ''<cat''"' # \set gpb '\\g | gnuplot -e "set terminal dumb; plot ''<cat'' w boxes"' -- set output format # \t on \\\pset format unaligned \\\f '\t' # select x * cos(x * pi()), x * sin(x * pi()) from generate_series(-2.0, 2.0, 0.01) as x :gpp # select x, random() * random() from generate_series(1, 100) as x :gpb


定義した変数名・内容の確認は ↓ メタコマンド
# \set ... gpp = '\g | gnuplot -e "set terminal dumb; plot '<cat'"' gpb = '\g | gnuplot -e "set terminal dumb; plot '<cat' w boxes"'
対話モード(gnuplot のシェルに入り、作業後に psql に戻る)
今回の例えば ↓ 「\g
-- set output format # \t on \\\pset format unaligned \\\f '\t' # select x, random() * random() from generate_series(1, 100) as x # \g tmp.dat \\\! gnuplot -e "d='tmp.dat'; set terminal dumb;" - gnuplot> p d w boxes(= plot d with boxes) gnuplot> p d using 1 w boxes gnuplot> ... gnuplot> ... (plot as you want) gnuplot> exit # \! rm tmp.dat


上のように
当初、gnuplot
# select x, sum(random()) over(order by x) / x from generate_series(1, 1000) as x # \g tmp.dat \\\! gnuplot -e "d='tmp.dat'; set terminal dumb" --persist # # \g tmp.dat \\\! gnuplot -e "d='tmp.dat'; set terminal dumb" -

さすがに