私ができる少なくともので - 最初plot
は何とかもstdout
または/dev/null
、ファイルへのアウトfinding maximum value in a data set and subtracting from plot - comp.graphics.apps.gnuplot | Google Groupsポイント、1 できplot
として、しかし:)
その後秒を台無しにし、プレーンなASCII形式のテーブルを取得することを考え、ことを嫌いますその方法で最初の通話をリダイレクトするので、行動に干渉しません2番目の呼び出しのターミナルをplot
にプロットします。
そこで、以下「inline.dat
」データセットの最初の列の最初の要素を介して取得された他のコード例は、次のとおりですので、次にプロットは直接にfirst
によって相殺することができる
# print and get (in _drcv) first value of first data column:
eval print_dataset_row_column("inline.dat",0,1)
# must "copy" the "return" value manually:
first = _drcv
... plot
コール。
注意が再びprint_dataset_row_column
呼び出しplot
は(set table
/dev/null
に経由してリダイレクト)することを - そのように、あなたはそれを呼び出す各時間が単一値を取得するには、それは全体データセットによる反復処理が発生します!だから、最初の要素と最後の要素(そしておそらくsome basic statistics with gnuplotのような他の要素)が必要な場合は、print_dataset_row_column
を書き直して、一度にすべての要素を取得する方が良いでしょう。
また、データセットに特殊なフォーマットを使用し、using
行を書き換える場合は、print_dataset_row_column
書き換えが必要です。この例では、3番目の列は文字列です。デフォルトではプロットデータ列として受け入れられません。そのため、print_dataset_*
関数の呼び出しは処理する必要があります(gnuplot plot from stringも参照してください)。このスクリプトが呼び出されると
# generate data
system "cat > ./inline.dat <<EOF\n\
10.0 1 a 2\n\
10.2 2 b 2\n\
10.4 3 a 2\n\
10.6 4 b 2\n\
10.8 5 c 7\n\
11.0 5 c 7\n\
EOF\n"
### "dry-run" functions:
# iterate through dataset by calling
# `plot`, redirected to file output (via `set table`)
#
# note: eval (not print) cannot be inside a user-defined function:
# a(b) = eval('c=3') ; print a(4) ==> "undefined function: eval"
# nor you can make multistatement functions with semicolon:
# f(x) = (2*x ; x=x+2) ==> ')' expected (at ';')
#
# so these functions are defined as strings - and called through eval
#
# through a single column spec in `using`:
# (`plot` prints table to stdout)
#
print_dataset_column(filename,col) = "set table '/dev/stdout' ;\
plot '".filename."' using ".col." ;\
unset table"
#
# through two column spec in `using`:
# (`plot` prints table to stdout)
#
print_dataset_twocolumn(filename,colA,colB) = "set table '/dev/stdout' ;\
plot '".filename."' using ".colA.":".colB." ;\
unset table"
#
# print value of row:column in dataset, saving it as _drcv variable
#
# init variable
#
_drcv = 0
#
# create _drc helper function; note assign and "return" in
# true branch of ternary clause
#
_drc(ri, colval, col) = (ri == _row) ? _drcv = colval : colval
#
# define the callable function:
#
print_dataset_row_column(filename,row,col) = "_row = ".row." ;\
set table '/dev/null' ;\
plot '".filename."' using (_drc($0, $".col.", ".col.")) ;\
unset table ;\
print '".filename."[r:".row.",c:".col."] = ',_drcv"
#
#
### end dry run functions
#
# test print_dataset_* functions:
#
eval print_dataset_column("inline.dat",0)
eval print_dataset_twocolumn("inline.dat",0,0)
# string column - cannot directly:
# set table '/dev/stdout' ;plot 'inline.dat' using 3 ;unset table
# ^
# line 69: warning: Skipping data file with no valid points
# line 69: x range is invalid
#~ eval print_dataset_column("inline.dat",3)
eval print_dataset_column("inline.dat",1)
eval print_dataset_twocolumn("inline.dat",1,2)
eval print_dataset_row_column("inline.dat",4,1)
eval print_dataset_row_column("inline.dat",4,2)
# will fail - 3 is string column
# line 82: warning: Skipping data file with no valid points
# line 82: x range is invalid
#~ eval print_dataset_row_column("inline.dat",4,3)
#
# do a plot offset by first element position
#
# print and get (in _drcv) first value of first data column:
eval print_dataset_row_column("inline.dat",0,1)
# must "copy" the "return" value manually:
first = _drcv
# ranges
set yrange [0:8]
set xrange [0:11.5]
# plot finally:
plot "inline.dat" using ($1-first):2 with impulses linewidth 2
、OPでのデータセットは0から始まる、移動プロットされて - と、次のはtest.gp
それを呼びましょう - だからここ
は、サンプルコードです
gnuplot> load './test.gp'
# Curve 0 of 1, 6 points
# Curve title: "'inline.dat' using 0"
# x y type
0 0 i
1 1 i
2 2 i
3 3 i
4 4 i
5 5 i
# Curve 0 of 1, 6 points
# Curve title: "'inline.dat' using 0:0"
# x y type
0 0 i
1 1 i
2 2 i
3 3 i
4 4 i
5 5 i
# Curve 0 of 1, 6 points
# Curve title: "'inline.dat' using 1"
# x y type
0 10 i
1 10.2 i
2 10.4 i
3 10.6 i
4 10.8 i
5 11 i
# Curve 0 of 1, 6 points
# Curve title: "'inline.dat' using 1:2"
# x y type
10 1 i
10.2 2 i
10.4 3 i
10.6 4 i
10.8 5 i
11 5 i
inline.dat[r:4,c:1] = 10.8
inline.dat[r:4,c:2] = 5.0
inline.dat[r:0,c:1] = 10.0
:端子に出力(最初のいくつかのテーブル印刷物はstdout
にset table
plot
介してリダイレクトからの実際の出力されます)
大変 - 簡潔な回答をいただき、ありがとうございました。 – sdaau
はい、ただし、必ずしも最小限にする必要はないデータ系列の*最初の要素に興味があればどうしますか? – TMOTTM
@TMOTTMの場合、最初の要素だけを使用するように外部スクリプトを調整する必要があります(awkをソート部分なしで直接使用する)。 – EverythingRightPlace