MENU

溶けかけてるうさぎ HP GALLERY BLOG TOP RECENT ARTICLES POPULAR ARTICLES ABOUT THIS BLOG

CATEGORY

大学 (140) 仕事 (17) 航空宇宙 (104) 写真 (77) 旅行 (32) 飯・酒 (17) コンピュータ (118) その他 (44)

TAG

ARCHIVE

RECENT

【カメラ】X100 シリーズが好きすぎる(主にリーフシャッタ) 【カメラ】X100V から X100VI に買い替えました 【自宅サーバー】Google Domains から Cloudflare にドメインを移管 【カメラ】FUJIFILM XF レンズのサイズ比較ができるようにしてみた 【写真】自作写真閲覧ページにてフィルムシミュレーションで写真をフィルタできるようにした

【gnuplot】横軸共通な複数グラフプロットのコマンドセット

事象発生日:2019-06-30

記事公開日:2019-06-30

アクセス数:20790

gnuplotのコマンドセットの備忘録 その5.

 

横軸共通でのmultiplot,頻繁には使わないので覚えないけど,ちょくちょく使うときに調べるのがめんどくさいので,ここに残しておく.

1.実行環境

Microsoft Windows 10 Home (64bit)

Gnuplot Version 5.2 patchlevel 0

2.データフォーマット

とりあえず例として,折れ線x2を3枚描画するので,単純な時刻+1次元データx6である.

データファイル (data.dat [4,839 byte])

t0    x1-0  y1-0  x2-0  y2-0  x3-0  y3-0
t1    x1-1  y1-1  x2-1  y2-1  x3-1  y3-1
:     :     :     :     :     :     :
データファイル

3.コマンドセットと出力

height = 0.28
lms  = 0.10
rms  = 0.97
hms  = 0.03

bms3 = 0.08
tms3 = bms3 + height
bms2 = tms3 + hms
tms2 = bms2 + height
bms1 = tms2 + hms
tms1 = bms1 + height

sizex = 6
sizey = 4

set tics    font "Consolas,12"
set key     font "Consolas,12"
set title   font "Consolas,12"
set label   font "Consolas,12"
set xlabel  font "Consolas,12"
set ylabel  font "Consolas,12"
#set zlabel  font "Consolas,12"
#set y2label font "Consolas,12"
#set cblabel font "Consolas,12"

set terminal pdf enhanced color size sizex in, sizey in
set output "plot.pdf"

set multiplot

set format y "%4.0f"

set lmargin screen lms
set rmargin screen rms
set tmargin screen tms1
set bmargin screen bms1

set label 1 " (a) Control Input" at graph 0.02,0.92 left
set xlabel ""
set ylabel "acceleration [m/s^2]"
set format x ""
set format y "%3.1f"
set ytics 1.5

plot \
  "data.dat" u ($1):($4)  ti "x"  w l  , \
  "data.dat" u ($1):($7)  ti "y"  w l


set lmargin screen lms
set rmargin screen rms
set tmargin screen tms2
set bmargin screen bms2

set label 1 " (b) Position" at graph 0.02,0.92 left
set xlabel ""
set ylabel "position [m]"
set format x ""
set ytics 0.5
set format y "%3.1f"

plot \
  "data.dat" u ($1):($2)  ti "x"  w l  , \
  "data.dat" u ($1):($5)  ti "y"  w l


set lmargin screen lms
set rmargin screen rms
set tmargin screen tms3
set bmargin screen bms3

set label 1 " (c) velocity" at graph 0.02,0.92 left
set xlabel "time [s]" offset 0,1.2
set ylabel "velocity [m/s]"
set format x "%g"
set ytics 0.5
set xtics offset 0,0.3
set format y "%3.1f"

plot \
  "data.dat" u ($1):($3)  ti "x"  w l  , \
  "data.dat" u ($1):($6)  ti "y"  w l


unset multiplot

set output
set terminal wxt
コマンドセット
PDF出力画像

4.Tips

パラメタ類を設定

gnuplotではユーザー定義の変数が使用できる.

そこで,はじめに変数を定義してしまう.

height = 0.28
lms  = 0.10
rms  = 0.97
hms  = 0.03

bms3 = 0.08
tms3 = bms3 + height
bms2 = tms3 + hms
tms2 = bms2 + height
bms1 = tms2 + hms
tms1 = bms1 + height

sizex = 6
sizey = 4

フォント・フォントサイズを変更

set tics    font "Consolas,12"
set key     font "Consolas,12"
set title   font "Consolas,12"
set label   font "Consolas,12"
set xlabel  font "Consolas,12"
set ylabel  font "Consolas,12"
#set zlabel  font "Consolas,12"
#set y2label font "Consolas,12"
#set cblabel font "Consolas,12"

出力画像のサイズ,フォーマットを指定

set terminal pdf enhanced color size sizex in, sizey in
set output "plot.pdf"

multiplot

複数のグラフを一枚にまとめる方法として,set multiplotset multiplot layoutの2種類あるが,後者は自動配置なため,細かな設定ができない.

そこでここでは前者を用いて,マージンを細く設定することによって,複数のグラフを統合した.

これらはを参考にした.

set multiplot
unset multiplot

で,multiplot環境をセット.

 

この間で3枚のグラフを描画させている.

軸ラベルを消す

set xlabel ""
set xlabel ""

のようにして軸ラベルを消している.

任意の場所に文字を挿入

set label 1 " (a) Control Input" at graph 0.02,0.92 left

のように任意の場所に文字を挿入できる.

なお,at graphとすることで,グラフサイズを1とした相対座標で位置を指定できる.

軸ラベル,メモリの位置の微調整

set xlabel "time [s]" offset 0,1.2
set xtics offset 0,0.3

と,offset ,で位置の微調整ができる.

5.出典サイト

Official gnuplot documentation. gnuplot 5.0. Retrieved October 11, 2017, from http://www.gnuplot.info/docs_5.0/gnuplot.pdf

関連記事

コメントを投稿

名前

Email (※公開されることはありません)

コメント