〜 gnuplot4.6にて作成 〜
〔ヒストグラム・度数分布多角形用〕
#11_ini.txt の中身
unset key
set style fill solid border lc rgb "black"
set grid xtics
set xtics 5 #縦の格子線を5メモリずつに
set grid ytics
set ytics 10 #y軸の主目盛の間隔を10メモリずつに
set grid mytics
set mytics 10 #y軸の主目盛の間隔を10等分して、副目盛を割り当てる
set grid lt -1 lw 2 , lt -1 lw 1 #主格子線と副格子線の線種と太さの設定
set style line 2 lc rgbcolor "black" lw 3 pt 7 ps 0.8 #折れ線用のスタイル
set style line 3 lc rgb "light-cyan" lw 2 #ヒストグラム用のスタイル
上の設定値をテキストファイルとして保存します。ファイル名は任意ですが、今回の例では「11_ini.txt」名で保存したものとして説明しています。loadコマンドで呼び出すとグラフをすぐに作成できます。(callでも可)
〔関数グラフ用〕
【loadコマンド用スクリプト】
#01_ini.txt の中身
a1=8 #表示領域の変数設定:x軸の正の方向(左例だと8まで)
a2=9 #表示領域の変数設定:y軸の正の方向(左例だと9まで)
a3=-7 #表示領域の変数設定:x軸方向の負の方向(左例だと-7まで)
a4=-6 #表示領域の変数設定:y軸の負の方向(左例だと-6まで)
unset key
set zeroaxis lt -1 lw 2
set xtics axis
set ytics axis
set x2tics axis
set y2tics axis
set format x2 ""
set format y2 ""
set x2tics 1
set y2tics 1
set size ratio -1
set xtics ('-15' -15 ,'-10' -10 ,'' 0, '-5' -5, '5' 5 ,'10' 10 , '15' 15)
set ytics ('-15' -15 ,'-10' -10 ,'' 0, '-5' -5, '5' 5 ,'10' 10 , '15' 15)
set grid x2tics lt -1 lw 0.9 #グリッド線の線種、太さの設定
set grid y2tics lt -1 lw 0.9 #グリッド線の線種、太さの設定
set grid lc rgbcolor "black"
set grid noxtics x2tics noytics y2tics
set tics scale 0
set style line 1 lc rgbcolor "black" lw 1.6 # グリッド線の線種
set xrange [a3:a1]
set yrange [a4:a2]
set style arrow 2 size character 1.5,20 filled #矢印のスタイル設定
set arrow 1 from a3,0 to a1,0 lw 1.8 arrowstyle 2 #矢印設定x軸
set arrow 2 from 0,a4 to 0,a2 lw 1.8 arrowstyle 2 #矢印設定y軸
set xtics offset 0 , graph 0.01 #x軸の目盛の数字の位置調整
set ytics offset 0 , graph 0.02 #y軸の目盛の数字の位置調整
set tics font "symbol,17" #数字のフォントの種類とサイズ
上の設定値を「01_ini.txt」として保存して、loadコマンドで呼び出すとグラフをすぐに作成できます。
【callコマンド用スクリプト (loadコマンドではエラーが出ます)】
#02_ini.txt の中身(gnuplot 4 用)
a1=$0 #表示領域の変数設定:x軸の正の方向
a2=$1 #表示領域の変数設定:y軸の正の方向
a3=-1*$2 #表示領域の変数設定:x軸方向の負の方向
a4=-1*$3 #表示領域の変数設定:y軸の負の方向
unset key
set zeroaxis lt -1 lw 2
set xtics axis
set ytics axis
set x2tics axis
set y2tics axis
set format x2 ""
set format y2 ""
set x2tics 1
set y2tics 1
set size ratio -1
set xtics ('-15' -15 ,'-10' -10 ,'' 0, '-5' -5, '5' 5 ,'10' 10 , '15' 15)
set ytics ('-15' -15 ,'-10' -10 ,'' 0, '-5' -5, '5' 5 ,'10' 10 , '15' 15)
set grid x2tics lt -1 lw 0.9 #グリッド線の線種、太さの設定
set grid y2tics lt -1 lw 0.9 #グリッド線の線種、太さの設定
set grid lc rgbcolor "black"
set grid noxtics x2tics noytics y2tics
set tics scale 0
set style line 1 lc rgbcolor "black" lw 1.6 # グリッド線の線種
set xrange [a3:a1]
set yrange [a4:a2]
set style arrow 2 size character 1.5,20 filled #矢印のスタイル設定
set arrow 1 from a3,0 to a1,0 lw 1.8 arrowstyle 2 #矢印設定x軸
set arrow 2 from 0,a4 to 0,a2 lw 1.8 arrowstyle 2 #矢印設定y軸
set xtics offset 0 , graph 0.01 #x軸の目盛の数字の位置調整
set ytics offset 0 , graph 0.02 #y軸の目盛の数字の位置調整
set tics font "symbol,17" #数字のフォントの種類とサイズ
【2017.11 追記】gnuplot 5 では上記のものではエラーが出ます。
gnuplot5 では以下のものを使用のこと。
a1=@ARG1 #表示領域の変数設定:x軸の正の方向
a2=@ARG2 #表示領域の変数設定:y軸の正の方向
a3=-1*@ARG3 #表示領域の変数設定:x軸方向の負の方向
a4=-1*@ARG4 #表示領域の変数設定:y軸の負の方向
unset key
set zeroaxis lt -1 lw 2
set xtics axis
set ytics axis
set x2tics axis
set y2tics axis
set format x2 ""
set format y2 ""
set x2tics 1
set y2tics 1
set size ratio -1
set xtics ('-15' -15 ,'-10' -10 ,'' 0, '-5' -5, '5' 5 ,'10' 10 , '15' 15)
set ytics ('-15' -15 ,'-10' -10 ,'' 0, '-5' -5, '5' 5 ,'10' 10 , '15' 15)
set grid x2tics lt -1 lw 0.9 #グリッド線の線種、太さの設定
set grid y2tics lt -1 lw 0.9 #グリッド線の線種、太さの設定
set grid lc rgbcolor "black"
set grid noxtics x2tics noytics y2tics
set tics scale 0
set style line 1 lc rgbcolor "black" lw 1.6 # グリッド線の線種
set xrange [a3:a1]
set yrange [a4:a2]
set style arrow 2 size character 1.5,20 filled #矢印のスタイル設定
set arrow 1 from a3,0 to a1,0 lw 1.8 arrowstyle 2 #矢印設定x軸
set arrow 2 from 0,a4 to 0,a2 lw 1.8 arrowstyle 2 #矢印設定y軸
set xtics offset 0 , graph 0.01 #x軸の目盛の数字の位置調整
set ytics offset 0 , graph 0.02 #y軸の目盛の数字の位置調整
set tics font "symbol,17" #数字のフォントの種類とサイズ
上の設定値を「02_ini.txt」として保存して、callコマンドを使用のこと。
「call "./02_ini.txt" 7 12 7 6」の後ろの赤の4つの数字はx軸正方向、y軸正方向、x軸負の方向、y軸負の方向の表示範囲の設定値です。表示範囲は任意で変更可能です。
load用スクリプトと違って、call用は表示範囲の変更のために、わざわざスクリプトを書き換える必要はありません。
gnuplotはスクリプトが扱えるようになると非常に便利です。
gnuplotのスクリプトについては以下のサイトが詳しいです。
興味のある方は読まれることをお薦めします。
〔外部サイト〕
・gnuplotスクリプトファイルに関するTips
・米澤進吾:gnuplotのスクリプト
・gnuplot version 5.0においてcall関数の引数の受け渡しで起きるエラーの回避法。
(gnuplot 5 の @ARG のことが書いてありました。)
関連記事
・gnuplot グラフ-座標平面づくり
・gnuplot でヒストグラム・度数分布多角形づくり
・gnuplot で eps 取扱いメモ
・個人的gnuplot用スクリプトその2(ファイル保存〜使用方法まで)
● ブログ記事目次