LoginSignup
7
6

More than 5 years have passed since last update.

gnuplotのスクリプトに引数を渡す

Posted at

gnuplotのスクリプトに引数を直接渡す方法はないが、-eオプションを使うと似たようなことができる。

gnuplotのmanで-eオプションを調べると以下のように書いてある。

-e "command list" executes the requested commands before loading the next input file.

例えば、以下のようにして -eオプションで変数indir, outdirをスクリプトの実行前に定義することにより、スクリプト myscript.plt 内で変数indir,outdirを参照できる。

gnuplot -e "indir='input'; outdir='$OUTPUT_DIR'" myscript.plt

gnuplotは-eで渡される文字列を評価しているだけなので、複数の変数を定義したい場合は";"でわけるようにする。

myscript.plt
set terminal png
set output outdir."/my_plot.png"
plot indir."/my_data.dat"

ちなみに、文字列型の変数を連結するには "." を用いる。変数.文字列とすると文字列を連結できる。

参考 : http://stackoverflow.com/questions/12328603/how-to-pass-command-line-argument-to-gnuplot

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6