我永远无法让循环和布局都能正常工作。 我的数据看起来像这样
2 1 -93.50882606 -93.51697017 -93.51086209
2 2 -93.51324833 -93.51714636 -93.51422284
2 3 -93.52672325 -93.53627468 -93.52911111
2 4 -93.51306982 -93.52395431 -93.51579094
2 5 -93.50908482 -93.51902598 -93.51157011
2 6 -93.50825891 -93.51587124 -93.51016199
2 7 -93.50822884 -93.51691667 -93.51040080
3 1 -93.50792762 -93.51624138 -93.51000606
3 2 -93.51196983 -93.51499451 -93.51272600
3 3 -93.50793572 -93.51664664 -93.51011345
3 4 -93.50768256 -93.51618396 -93.50980791
3 5 -93.50771675 -93.51656535 -93.50992890
4 1 -93.50762338 -93.51564665 -93.50962919
4 2 -93.53234566 -93.54136850 -93.53460137
我想要使用2,3,4,5列的值,直到第一列的值发生变化。然后它应该在它下面开始一个新的多重时隙。
第一列中的数字总是不同的,所以我不知道如何制作循环而不知道有多少会在固定数量上设置多色布局
答案 0 :(得分:1)
这很可能需要对输入文件进行一些外部处理。一种方法可以如下
reset
set terminal pngcairo enhanced
set output 'fig.png'
set xtics out nomirror
set ytics out nomirror
set ytics format '%.3f'
set xr [1:7]
set key bottom right
#find the number of unique (consecutive) values from the first column
N = system("gawk '{print $1}' input.dat | uniq | wc -l")
#adjust multiplot setup
set multiplot layout N, 1
do for [i=1:N] {
#find the corresponding group identifier
idx = system(sprintf("gawk '{print $1}' input.dat | uniq | head -n%d | tail -n1", i))
set title sprintf("group %s", idx)
plotCmd=sprintf("<gawk 'BEGIN{p=v=0;} {if(!p||$1!=v){v=$1;p+=1} if(p==%d){print p,$2,$3,$4,$5} if(p>%d){exit;}}' input.dat", i, i)
plot \
plotCmd u 2:3 w l lc rgb 'black' t 'column 3', \
'' u 2:4 w l lc rgb 'dark-red' t 'column 4', \
'' u 2:5 w l lc rgb 'royalblue' t 'column 5'
}
策略是: