Skip to content

Instantly share code, notes, and snippets.

@TakashiUNUMA
Last active July 21, 2017 07:30
Show Gist options
  • Save TakashiUNUMA/5704035 to your computer and use it in GitHub Desktop.
Save TakashiUNUMA/5704035 to your computer and use it in GitHub Desktop.
A template bash script for gnuplot.
#!/bin/sh
# 描画する元のデータを指定 (gnuplot スクリプトへ引き継がれる)
infile=input.txt
# bash ファイル内での出力ファイル名を指定 (gnuplot スクリプトへ引き継がれる)
epsfile=output.eps
cat > tmp.gnuplot << EOF
# 出力を eps color enhanced に指定するためのおまじない
set term postscript eps color enhanced "Helvetica,24"
# 出力 eps 名を指定 (bash 変数を引き継ぐ)
set output "${epsfile}"
# 描画範囲の初期化
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
# 描画範囲
set lmargin 7.5
set rmargin 3
set tmargin 3
set bmargin 4
# フォント設定
#set tics font 'Helvetica,20'
#set xtics font 'Helvetica,18'
#set ytics font 'Helvetica,18'
#set title font 'Helvetica,24'
#set label font 'Helvetica,20'
# 軸ラベル
set xlabel "One hour accumulated rainfall [mm]"
set ylabel "Number of counts"
# 軸目盛りのフォーマット
#set format x "10^{%L}"
set format y "10^{%L}"
set style fill solid 1.0
# 描画範囲指定
set xrange [-5:100]
set yrange [1:1000]
# 対数軸の指定
#set logscale x
set logscale y
# 対数目盛りは偶数桁のみ
#set mxtics 10
#set mytics 10
#set xtics 50
#set ytics 10
# グリッドを描画
set grid xtics ytics mytics
# アスペクト比 1:1
#set size square
# 凡例なし
#unset key
# 頻度分布の場合,幅を調整
#set boxwidth 0.8 relative
# 描画
plot "${infile}" using 1:2 with lines lw 8 lc 0 title "TITLE"
EOF
# execute gnuplot
gnuplot -persist tmp.gnuplot
rm -f tmp.gnuplot
# convert from eps to png (ps2raster is required to execute)
#ps2raster -Tg -E600 ${epsfile}
#ps2raster -Tf ${epsfile}
#rm -f ${epsfile}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment