ルギア君の戯言

雑多な記事。

gnuplot

gnuplot> show version

        G N U P L O T
        Version 4.3 patchlevel 0
        last modified November 2008
        System: Linux 2.6.29.6-10m.mo6.i686.PAE

        Copyright (C) 1986 - 1993, 1998, 2004, 2007, 2008
        Thomas Williams, Colin Kelley and many others

        Type `help` to access the on-line reference manual.
        The gnuplot FAQ is available from
                http://www.gnuplot.info/faq/

        Send comments and help requests to  <gnuplot-beta@lists.sourceforge.net>
        Send bug reports and suggestions to <gnuplot-beta@lists.sourceforge.net>

gnuplot> !rpm -q gnuplot
gnuplot-4.3.0-0.0.20081121.2m.mo6.i686
!

な GNUPLOT にて eps 画像と文字の部分を latex で出す epslatex を用いて出力すると、

gnuplot> set terminal epslatex
Terminal type set to 'epslatex'
Options are '   leveldefault monochrome blacktext \
   dashed dashlength 1.0 linewidth 1.0 butt \      
   palfuncparam 2000,0.003 \                       
   noheader "" 11 '                                
gnuplot> set output "test.tex"
gnuplot> plot x**2            
gnuplot> !cat test.tex
% GNUPLOT: LaTeX picture with Postscript
\begingroup                             
  \makeatletter                         
  \providecommand\color[2][]{%          
    \GenericError{(gnuplot) \space\space\space\@spaces}{%
      Package color not loaded in conjunction with       
      terminal option `colourtext'%                      
    }{See the gnuplot documentation for explanation.%    
    }{Either use 'blacktext' in gnuplot or load the package
      color.sty in LaTeX.}%                                
    \renewcommand\color[2][]{}%                            
  }%                                                       
  \providecommand\includegraphics[2][]{%                   
    \GenericError{(gnuplot) \space\space\space\@spaces}{%  
      Package graphicx or graphics not loaded%             
    }{See the gnuplot documentation for explanation.%      
    }{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
    \renewcommand\includegraphics[2][]{}%                                
  }%                                                                     
  \providecommand\rotatebox[2]{#2}%                                      
  \@ifundefined{ifGPcolor}{%                                             
    \newif\ifGPcolor                                                     
    \GPcolorfalse                                                        
  }{}%                                                                   
  \@ifundefined{ifGPblacktext}{%                                         
    \newif\ifGPblacktext                                                 
    \GPblacktexttrue                                                     
  }{}%                                                                   
  % define a \g@addto@macro without @ in the name:                       
  \let\gplgaddtomacro\g@addto@macro                                      
  % define empty templates for all commands taking text:                 
  \gdef\gplbacktext{}%                                                   
  \gdef\gplfronttext{}%                                                  
  \makeatother                                                           
  \ifGPblacktext                                                         
    % no textcolor at all                                                
    \def\colorrgb#1{}%                                                   
    \def\colorgray#1{}%                                                  
  \else                                                                  
    % gray or color?                                                     
    \ifGPcolor                                                           
      \def\colorrgb#1{\color[rgb]{#1}}%                                  
      \def\colorgray#1{\color[gray]{#1}}%                                
      \expandafter\def\csname LTw\endcsname{\color{white}}%              
      \expandafter\def\csname LTb\endcsname{\color{black}}%              
      \expandafter\def\csname LTa\endcsname{\color{black}}%              
      \expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%         
      \expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%         
      \expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%         
      \expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%         
      \expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%         
      \expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%         
      \expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%         
      \expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%       
      \expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%   
    \else                                                                
      % gray                                                             
      \def\colorrgb#1{\color{black}}%                                    
      \def\colorgray#1{\color[gray]{#1}}%                                
      \expandafter\def\csname LTw\endcsname{\color{white}}%              
      \expandafter\def\csname LTb\endcsname{\color{black}}%
      \expandafter\def\csname LTa\endcsname{\color{black}}%
      \expandafter\def\csname LT0\endcsname{\color{black}}%
      \expandafter\def\csname LT1\endcsname{\color{black}}%
      \expandafter\def\csname LT2\endcsname{\color{black}}%
      \expandafter\def\csname LT3\endcsname{\color{black}}%
      \expandafter\def\csname LT4\endcsname{\color{black}}%
      \expandafter\def\csname LT5\endcsname{\color{black}}%
      \expandafter\def\csname LT6\endcsname{\color{black}}%
      \expandafter\def\csname LT7\endcsname{\color{black}}%
      \expandafter\def\csname LT8\endcsname{\color{black}}%
    \fi
  \fi
  \setlength{\unitlength}{0.0500bp}%
  \begin{picture}(7200.00,5040.00)%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%
      \put(726,440){\makebox(0,0)[r]{\strut{} 0}}%
      \put(726,874){\makebox(0,0)[r]{\strut{} 10}}%
      \put(726,1307){\makebox(0,0)[r]{\strut{} 20}}%
      \put(726,1741){\makebox(0,0)[r]{\strut{} 30}}%
      \put(726,2174){\makebox(0,0)[r]{\strut{} 40}}%
      \put(726,2608){\makebox(0,0)[r]{\strut{} 50}}%
      \put(726,3041){\makebox(0,0)[r]{\strut{} 60}}%
      \put(726,3475){\makebox(0,0)[r]{\strut{} 70}}%
      \put(726,3908){\makebox(0,0)[r]{\strut{} 80}}%
      \put(726,4342){\makebox(0,0)[r]{\strut{} 90}}%
      \put(726,4775){\makebox(0,0)[r]{\strut{} 100}}%
      \put(858,220){\makebox(0,0){\strut{}-10}}%
      \put(2361,220){\makebox(0,0){\strut{}-5}}%
      \put(3864,220){\makebox(0,0){\strut{} 0}}%
      \put(5366,220){\makebox(0,0){\strut{} 5}}%
      \put(6869,220){\makebox(0,0){\strut{} 10}}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%
      \put(5882,4602){\makebox(0,0)[r]{\strut{}x**2}}%
    }%
!
gnuplot>

のように途中で切れてしまう*1んだが、例えば

[lugia@lugia-castle 光電変換素子の分光特性]$ cat fig3.gplt
h=6.6260693e-34                                           
c=2.99792458e+8                                           
k=1.3806505e-23                                           
e(l)=8*pi*h*c/((l*1e-9)**5)/(exp(h*c/(l*1e-9*k*2300))-1)  

set terminal epslatex
set xrange [200:4000]
set output "fig3.tex"
plot e(x)            
[lugia@lugia-castle 光電変換素子の分光特性]$ gnuplot fig3.gplt
[lugia@lugia-castle 光電変換素子の分光特性]$ cat fig3.tex
% GNUPLOT: LaTeX picture with Postscript                 
\begingroup                                              
  \makeatletter                                          
  \providecommand\color[2][]{%                           
    \GenericError{(gnuplot) \space\space\space\@spaces}{%
      Package color not loaded in conjunction with       
      terminal option `colourtext'%                      
    }{See the gnuplot documentation for explanation.%    
    }{Either use 'blacktext' in gnuplot or load the package
      color.sty in LaTeX.}%                                
    \renewcommand\color[2][]{}%                            
  }%                                                       
  \providecommand\includegraphics[2][]{%                   
    \GenericError{(gnuplot) \space\space\space\@spaces}{%  
      Package graphicx or graphics not loaded%             
    }{See the gnuplot documentation for explanation.%      
    }{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
    \renewcommand\includegraphics[2][]{}%                                
  }%                                                                     
  \providecommand\rotatebox[2]{#2}%                                      
  \@ifundefined{ifGPcolor}{%                                             
    \newif\ifGPcolor                                                     
    \GPcolorfalse                                                        
  }{}%                                                                   
  \@ifundefined{ifGPblacktext}{%                                         
    \newif\ifGPblacktext                                                 
    \GPblacktexttrue                                                     
  }{}%                                                                   
  % define a \g@addto@macro without @ in the name:                       
  \let\gplgaddtomacro\g@addto@macro                                      
  % define empty templates for all commands taking text:                 
  \gdef\gplbacktext{}%                                                   
  \gdef\gplfronttext{}%                                                  
  \makeatother                                                           
  \ifGPblacktext                                                         
    % no textcolor at all                                                
    \def\colorrgb#1{}%                                                   
    \def\colorgray#1{}%                                                  
  \else                                                                  
    % gray or color?                                                     
    \ifGPcolor                                                           
      \def\colorrgb#1{\color[rgb]{#1}}%                                  
      \def\colorgray#1{\color[gray]{#1}}%                                
      \expandafter\def\csname LTw\endcsname{\color{white}}%              
      \expandafter\def\csname LTb\endcsname{\color{black}}%              
      \expandafter\def\csname LTa\endcsname{\color{black}}%              
      \expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%         
      \expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%         
      \expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%         
      \expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%         
      \expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%         
      \expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%         
      \expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%         
      \expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%       
      \expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%   
    \else                                                                
      % gray                                                             
      \def\colorrgb#1{\color{black}}%                                    
      \def\colorgray#1{\color[gray]{#1}}%                                
      \expandafter\def\csname LTw\endcsname{\color{white}}%              
      \expandafter\def\csname LTb\endcsname{\color{black}}%              
      \expandafter\def\csname LTa\endcsname{\color{black}}%              
      \expandafter\def\csname LT0\endcsname{\color{black}}%              
      \expandafter\def\csname LT1\endcsname{\color{black}}%
      \expandafter\def\csname LT2\endcsname{\color{black}}%
      \expandafter\def\csname LT3\endcsname{\color{black}}%
      \expandafter\def\csname LT4\endcsname{\color{black}}%
      \expandafter\def\csname LT5\endcsname{\color{black}}%
      \expandafter\def\csname LT6\endcsname{\color{black}}%
      \expandafter\def\csname LT7\endcsname{\color{black}}%
      \expandafter\def\csname LT8\endcsname{\color{black}}%
    \fi
  \fi
  \setlength{\unitlength}{0.0500bp}%
  \begin{picture}(7200.00,5040.00)%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%
      \put(990,440){\makebox(0,0)[r]{\strut{} 0}}%
      \put(990,1163){\makebox(0,0)[r]{\strut{} 2000}}%
      \put(990,1885){\makebox(0,0)[r]{\strut{} 4000}}%
      \put(990,2608){\makebox(0,0)[r]{\strut{} 6000}}%
      \put(990,3330){\makebox(0,0)[r]{\strut{} 8000}}%
      \put(990,4053){\makebox(0,0)[r]{\strut{} 10000}}%
      \put(990,4775){\makebox(0,0)[r]{\strut{} 12000}}%
      \put(1576,220){\makebox(0,0){\strut{} 500}}%
      \put(2332,220){\makebox(0,0){\strut{} 1000}}%
      \put(3088,220){\makebox(0,0){\strut{} 1500}}%
      \put(3844,220){\makebox(0,0){\strut{} 2000}}%
      \put(4600,220){\makebox(0,0){\strut{} 2500}}%
      \put(5357,220){\makebox(0,0){\strut{} 3000}}%
      \put(6113,220){\makebox(0,0){\strut{} 3500}}%
      \put(6869,220){\makebox(0,0){\strut{} 4000}}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%
      \put(5882,4602){\makebox(0,0)[r]{\strut{}e(x)}}%
    }%
    \gplbacktext
    \put(0,0){\includegraphics{fig3}}%
    \gplfronttext
  \end{picture}%
\endgroup
[lugia@lugia-castle 光電変換素子の分光特性]$

って GNUPLOT スクリプトにすると問題なくできるみたい。


バグにみえるが、バグかというとそうでもないっぽい。


もう一度テストしてみたら、残りの部分は quit した時に書き込まれることが判明した・・・
でもいちいち quit しないといけないのか。

*1:例えば picture 環境が終わってない