gnuplotを使ってみる(実用編)

2011/06/17未分類import

gnuplotのインストールと設定

公式サイトをたどっていくとWindows版も入手できる.たどった先はたぶんこちら.最新版のWindowsバイナリをダウンロードして,好きなフォルダに解凍すればいい.
gnuplotは解凍後のフォルダのbinary内のwgnuplot.exeを実行する.
しかし,初回起動時はフォントの設定がなされていないために,文字が読めない!
ウィンドウを開いた直後に右クリックし,「Choose Font ...」を選択して設定する.
その後,再び右クリックして「Update C:\...」を実行して保存する.


設定ファイルとコマンドを使い分ける

gnuplotはコマンド単品を逐次実行していく以外に,設定ファイルを読み込ませて実行することができる.

使いそうな設定を書いておく
下記は2次元用
#gnuplot 設定ファイル

#グラフ書式 ラベル
set xlabel "x"
set ylabel "y"

#グラフ書式 描画範囲
set xrange [-10:10]
set yrange [-10:10]


#SVG ファイル出力
set terminal svg font "Meiryo,16" size 600,600
set output "svg-3d.svg"
#plot "data-test1.txt" with linespoints pt 7

次は3次元用
set xlabel "x"
set ylabel "y"
set zlabel "d"

#グラフ書式 描画範囲
set xrange [-100:100]
set yrange [-100:100]
set zrange [150:300]
set grid
set ticslevel 0

#出力設定
set pm3d
set view 60,206
set terminal svg font "Meiryo,16" size 600,600
set output "svg-3d.svg"
splot "data-test1.txt" with linespoints pt 7 
set terminal windows font "Meiryo,20" size 800,800
splot "data-test1.txt" with linespoints pt 7
データは次のようなもの.
#x	y	d
-100	0	200
-66	0	220
-33	0	270
0	0	250
33	0	260
66	0	220
100	0	180

0	-100	200
0	-66	220
0	-33	270
0	0	250
0	33	260
0	66	220
0	100	180

100	0	180
66	0	220
33	0	260
0	0	250
-33	0	270
-66	0	220
-100	0	200

0	100	180
0	66	220
0	33	260
0	0	250
0	-33	270
0	-66	220
0	-100	200
これを実行すると,こんなグラフが得られたりする(例なので形状などに意味はないです).
svg-3d-t2.jpg

GlibのWindowsにおけるインストールと…

2011/06/16未分類import
  1. GTK+の公式サイトからWindows版のGlibをダウンロードする(次の画像のGlib行のDev)
  2. ダウンロードしたファイルを解凍
  3. 解凍先のinclude\glib-2.0とlibの中身をフォルダ等そのまますべてC:MinGW32内のincludeとlibにコピーする.
  4. C:\MinGW32\lib\glib-2.0\includeにあるglibconfig.hをC:\MinGW32\includeにコピーする.
  5. インストール自体はこれで完了.コンパイルは可能になる.
  6. コンパイルは「gcc filename.c -lglib-2.0」のようにする(Windowsの時.Linuxは確認していない).
  7. コンパイルした後,実行するには下の画像の次の画像のGlib行のRun-timeにある「libglib-2.0-0.dll」というライブラリが実行ファイルと同じ場所になければならないのでそのようにする.

WS000000.JPG

解説サイト

日本語はC MAGAZINE Linux programming Tips 第9回 GLib プログラミング 前半
およびC MAGAZINE Linux programming Tips 第10回 GLib プログラミング 後半
英語の本家解説はGLib Reference Manual(リンク切れならこの辺りから探してください)です.

textextの代替

2011/05/18未分類import
残念ながら,inkscapeのバージョンを上げたらtextextが動作しなくなりました.
というわけで,代替のプログラム(というかバッチファイルを作成です.)
TeXのコードを実行すると,svgファイルとpngファイルが出来るはず.
textextよりは使い勝手は悪いですが,無いよりは遙かにマシです.
platex "%~1".tex
dvipsk -E -Ppdf "%~1".dvi -o "%~1".eps
gswin32c -q -sDEVICE=pbm -sOutputFile="%~1".pbm -r2400 -dNOPAUSE -dBATCH -dSAFER -dEPSCrop "%~1".eps
potrace -o "%~1".svg -s "%~1".pbm
convert "%~1".pbm "%~1"-res.png
convert "%~1"-res.png -resize 1500 "%~1"-toka.png
convert -transparent white "%~1"-toka.png "%~1".png
rm "%~1".aux
rm "%~1".log
rm "%~1"-res.png
rm "%~1".dvi
rm "%~1".eps
rm "%~1".pbm
dvipskは若干古い模様.5月に新規に導入したWindows版TeX環境では入っていませんでした.
ないなどと警告が出たときは,dvipsに書き換えてください.


ちなみに,これで読み込ませるTeXファイルは以下のようなものが良いかもしれません.
例を挙げます.
\documentclass{jarticle}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{txfonts}

\thispagestyle{empty}
\begin{document}
\begin{gather}
\begin{split}
\sigma&=\sigma_1\exp\left( -\dfrac{t}{\tau_1}\right)+\sigma_2\exp\left( -\dfrac{t}{\tau_2}\right)%\\
\end{split}
\nonumber
\end{gather}
\end{document}

imagemagickとpotraceのインストール

これをやらないと,上記バッチファイルは動きません.
ネットの海をさまよって,インストールしてください.
私はimagemagickの公式サイトのリンクから"ImageMagick-6.6.9-9-Q16-windows-dll.exe"
と,titleから"potrace-1.9.win32.zip"をダウンロードしました.

日本語の対応について

当初,私の環境では日本語が化けました.
対策ですが,C:\gs\gs9.02\lib以下のcidfmapを次のように記述したら直りました.
現在は日本語を入力することも可能な状態です.
%!
% cidfmap generated automatically by mkcidfm.ps from fonts found in
%   C:/Windows/Fonts

% Substitutions
/DFKaiShu-SB-Estd-BF << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/kaiu.ttf) /FileType /TrueType /SubfontID 0 >> ;
/Meiryo-BoldItalic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/meiryob.ttc) /FileType /TrueType /SubfontID 1 >> ;
/Meiryo << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/meiryo.ttc) /FileType /TrueType /SubfontID 0 >> ;
/MS-Gothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /FileType /TrueType /SubfontID 0 >> ;
/MicrosoftYaHei << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/msyh.ttf) /FileType /TrueType /SubfontID 0 >> ;
/GulimChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /FileType /TrueType /SubfontID 1 >> ;
/Gulim << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /FileType /TrueType /SubfontID 0 >> ;
/MalgunGothicRegular << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/malgun.ttf) /FileType /TrueType /SubfontID 0 >> ;
/PMingLiU << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/mingliu.ttc) /FileType /TrueType /SubfontID 1 >> ;
/MS-UI-Gothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /FileType /TrueType /SubfontID 2 >> ;
/FangSong << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simfang.ttf) /FileType /TrueType /SubfontID 0 >> ;
/NSimSun << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simsun.ttc) /FileType /TrueType /SubfontID 1 >> ;
/MalgunGothicBold << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/malgunbd.ttf) /FileType /TrueType /SubfontID 0 >> ;
/BatangChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /FileType /TrueType /SubfontID 1 >> ;
/DotumChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /FileType /TrueType /SubfontID 3 >> ;
/KaiTi << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simkai.ttf) /FileType /TrueType /SubfontID 0 >> ;
/MS-PGothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /FileType /TrueType /SubfontID 1 >> ;
/GungsuhChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /FileType /TrueType /SubfontID 3 >> ;
/Dotum << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /FileType /TrueType /SubfontID 2 >> ;
/Meiryo-Italic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/meiryo.ttc) /FileType /TrueType /SubfontID 1 >> ;
/MS-PMincho << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msmincho.ttc) /FileType /TrueType /SubfontID 1 >> ;
/Gungsuh << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /FileType /TrueType /SubfontID 2 >> ;
/SimSun << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simsun.ttc) /FileType /TrueType /SubfontID 0 >> ;
/MicrosoftYaHeiBold << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/msyhbd.ttf) /FileType /TrueType /SubfontID 0 >> ;
/MingLiU << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/mingliu.ttc) /FileType /TrueType /SubfontID 0 >> ;
/Batang << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /FileType /TrueType /SubfontID 0 >> ;
/Meiryo-Bold << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/meiryob.ttc) /FileType /TrueType /SubfontID 0 >> ;
/MicrosoftJhengHeiRegular << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/msjh.ttf) /FileType /TrueType /SubfontID 0 >> ;
/MS-Mincho << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msmincho.ttc) /FileType /TrueType /SubfontID 0 >> ;
/SimHei << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simhei.ttf) /FileType /TrueType /SubfontID 0 >> ;
/MicrosoftJhengHeiBold << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/msjhbd.ttf) /FileType /TrueType /SubfontID 0 >> ;

% Aliases
/AdobeSongStd-Light /SimSun ;
/MSung-Medium /MingLiU ;
/MSung-Light /MingLiU ;
/HYSMyeongJo-Medium /Batang ;
/STKaiti-Regular /KaiTi ;
/KozMinPr6N-Regular /MS-Mincho ;
/STHeiti-Regular /MicrosoftYaHei ;
/STFangsong-Light /FangSong ;
/AdobeMingStd-Light /MingLiU ;
/AdobeMyungjoStd-Medium /Batang ;
/MKai-Medium /DFKaiShu-SB-Estd-BF ;
/Ryumin-Light /MS-Mincho ;
/MHei-Medium /MicrosoftJhengHeiRegular ;
/HYGoThic-Medium /Dotum ;
/HYRGoThic-Medium /Gulim ;
/HeiseiMin-W3 /MS-Mincho ;
/Ryumin-Medium /MS-Mincho ;
/AdobeHeitiStd-Regular /MicrosoftYaHei ;
/HeiseiKakuGo-W5 /MS-Gothic ;
/STSong-Light /SimSun ;
/GothicBBB-Medium /MS-Gothic ;

TeXの索引の書式を変更する

2011/05/18未分類import
索引を比較的簡単に作成できるのは,TeXの強みの一つだと思う.
せっかく作ったのなら,その書式も自由に変更したいと考えるのは普通だろう.

その場合,istファイルというものを作る.内容はこんな感じ.
%group_skip "\bigskip"
lethead_flag 1
letter_head 2
symhead_positive "記号"
lethead_prefix "\n\\hfill{\\bfseries ---"
lethead_suffix "---}\\hfill\\hfill\\hfill\\hfill\\par\\nobreak"
これをmendex実行時にオプションで読み込ませる.
:!mendex -s sakuin-shoshiki.ist sakuin.idx  
以上.
なお,上のistファイルの内容だと,索引に五十音・ABCのそれぞれの先頭に「A」や「あ」などが表示される.