6.1 印刷用データの作成, LATEX への取り込み

gnuplot は通常は 画面に出力 (表示) するように なっているが、 変数 terminal (term と略記可能, 印刷データのフォーマット), output (データの出力先5) を 適当に設定することで印刷用のデータを作成できる。

gnuplot 起動直後は、 UNIX では、 termx11, outputSTDOUT になっている。 Windows では termwin になっている。 Mac では termaqua になっている (のかな? 手元の某マシンでは qt になっていた…悩ましい)。

印刷用データの形式として、UNIX 環境では、 多くの場合 PostScript が 適当であろう (他に tgif, eepic などが考えられる)。

UNIX 環境での印刷用 PostScript データの生成

gnuplot> plot besj0(x),besj1(x) ← Bessel 関数 $ J_0$, $ J_1$ のグラフを描く
gnuplot> show term ← terminal の確認 (通常は必要ない)
            terminal type is x11  
gnuplot> show output ← 出力先の確認 (通常は必要ない)
            output is sent to STDOUT  
gnuplot> set term postscript eps color ← terminal の指定
gnuplot> set output "bessel.eps" ← 出力ファイル名の指定
gnuplot> replot ← 直前の描画命令の再実行
gnuplot> set term x11 ← 少なくとも term は元に戻しておく
gnuplot> set output ← output を STDOUT に戻す (あるいは unset output)

とすると、bessel.eps という名前の EPS 形式のファイルが出力でき る。これは lp コマンドで直接プリンターに送っても印刷できるし 6LATEX 文書に次のようにして取り込むこともできる。
 \usepackage[dvips]{graphicx}% プリアンブルには、いつもこう書いておく
 ...
 \includegraphics[width=10cm]{bessel.eps}% bessel.eps を横幅 10cm で描く

Windows 環境でも大体同様だが、 termwin に戻すこと、 出力形式は PostScript ではなく、 PNG などの画像形式が良いかもしれない 7(set term png とするわけである)。 あるいは、Netpbm が使えるならば、 pbm, pgm, ppm などのドライバーを使う ことも考えられる (set terminal ppm とか)。

\includegraphics[width=10cm]{bessel.eps}

(2017/8/26) この文書も化石のようになってしまったけれど (それでも仕立て直しをする時間はないなあ…)、 Mac を使っているので少し補足。 Mac の場合、画面に出力するには、 termaqua とすべき場合が多いであろう。 こういうのを覚えるのが面倒ならば、
現在の状態を覚えておく
gnuplot> set term push
覚えておいた状態に戻す
gnuplot> set term pop
を活用すべきかもしれない (push, pop は知らないかなあ…)。 例えばこの項の最初の例は次のように簡略化(かつ環境非依存に)出来る。
簡略化バージョン
gnuplot> plot besj0(x),besj1(x) ← Bessel 関数のグラフを描く
gnuplot> set term push ←term の状態を覚えておく
gnuplot> set term postscript eps color ← terminal の指定
gnuplot> set output "bessel.eps" ← 出力ファイル名の指定
gnuplot> replot ← 直前の描画命令の再実行
gnuplot> set term pop ←termの状態を戻す。
gnuplot> set output ←output を STDOUT に戻す(省略可能)。

少なくとも termを元に戻しておけば (output を戻さなくても)、 画面表示出来るようである。

桂田 祐史