Fedora 31のgnuplotで日本語が入っているグラフを作成する

gnuplotでグラフを作ってみたが、日本語を入れるのに苦労したので、その手順の記録である。

1.Ghostscript での日本語対応

/usr/share/ghostscript/Resource/Init/cidfmap を編集し、以下の行を追加(要root権限

/Ryumin-Light << /FileType /TrueType /Path (/usr/share/fonts/ipa-ex-mincho/ipaexm.ttf) /CSI [(Japan1) 6] >> ;
/GothicBBB-Medium << /FileType /TrueType /Path (/usr/share/fonts/ipa-ex-gothic/ipaexg.ttf) /CSI [(Japan1) 6] >> ;

前提として、ipa-ex-mincho-fonts(/usr/share/fonts/ipa-ex-mincho/ipaexm.ttf 提供)とipa-ex-gothic-fonts(/usr/share/fonts/ipa-ex-gothic/ipaexg.ttf 提供)のパッケージが必要である。

 

2.以下のepsを生成するスクリプトファイルを用意する

 % test.plot

set terminal postscript enhanced color "GothicBBB-Medium-UniJIS-UTF8-H"
set output 'test.eps'

set grid #グリッドon

set xlabel "X軸"
set ylabel "Y軸"

plot sin(x) title 'サイン', cos(x) title 'コサイン'

 

3.以下のコマンドを実行して、test.epsを生成する

$ gnuplot test.plot

 生成したファイルはevinceかatrilコマンドから確認できる。イメージは以下である。

f:id:hanaokaiwa:20200206172916p:plain

生成した結果ファイル