Skip to content

Instantly share code, notes, and snippets.

@jico-rinho
Created July 26, 2019 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jico-rinho/6ac703c3343bc5fade17996436983379 to your computer and use it in GitHub Desktop.
Save jico-rinho/6ac703c3343bc5fade17996436983379 to your computer and use it in GitHub Desktop.
[gnuplot] 3-axis graph script
#for gnuplot
#http://www.gnuplot.info/
#"data.dat"はグラフデータ
reset
#latexで出力
set terminal tikz
set output "graph.tex"
#複数のグラフを書いて重ねる
set multiplot
#グラフの軸の位置を固定して共有する
set lmargin screen 0.1
set rmargin screen 0.85
set bmargin screen 0.95
set tmargin screen 0.05
#凡例を一致させるために用意
set style line 1 lt 1 pt 7
set style line 2 lt 2 pt 5 dt 2
set style line 3 lt 3 pt 9 dt 4
#x軸範囲
set xr [1000:4000]
#y1軸範囲
set yr [0:40.0]
#線図以外は書かない(重なるため)
unset key
set noxtics
set noytics
set noy2tics
unset border
#1st
plot \
"data.dat" using 1:3 smooth csplines ls 1 axis x1y1,\
"data.dat" using 1:3 ls 1 axis x1y1
#2nd
#y2軸範囲
set y2r [50:80]
plot \
"data.dat" using 1:2 smooth csplines ls 2 axis x1y2 notitle,\
"data.dat" using 1:2 ls 2 axis x1y2 notitle,\
#3rd
#y2軸範囲
set y2r [200:600]
plot \
"data.dat" using 1:4 smooth csplines ls 3 axis x1y2 notitle,\
"data.dat" using 1:4 ls 3 axis x1y2 notitle,\
#y2[50:80]軸を描画
set y2r [50:80]
#y2軸の描画範囲指定(開始地点,間隔,終了地点)
set y2tics 70,5,80
set my2tics 2
#ダミー描画でy2軸を描画する(y=1/0は描画されない)
plot 1/0 notitle
#枠 & 凡例 & x軸 & y軸 & y2[200:600]軸 描画
#枠設定
set border
#軸ラベル設定
set xl "回転数$n$[rpm]"
set yl "軸出力$N_\\mathrm b$[kW]"
set y2l "燃料消費率$b_\\mathrm e$[\\si{g/kW\\cdot h}]    トルク$T_\\mathrm b$[\\si{N\\cdot m}]"
#x軸設定
set xtics
set mxtics 2
#y軸設定
set ytics nomirror
set mytics 2
#y2[200:600]軸設定
set y2r [200:600]
set y2tics 200,50,300
set my2tics 2
#凡例設定
set key spacing 1.5
set key at 3900,20
set key box
#全部描画する
#凡例を描画するために同じline styleでtitleつけてダミー描画
plot 1/0 ls 1 w lp t "$N_\\mathrm b$",\
1/0 ls 2 w lp t "$T_\\mathrm b$",\
1/0 ls 3 w lp t "$b_\\mathrm e$"
#他に影響あったら嫌なのでモード解除
unset multiplot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment