用gnuplot绘制几个块数据的相同行号 [英] Plotting same line number of several blocks data with gnuplot
问题描述
我有一个具有以下结构的数据文件
I have a data file with the following structure
block1: line 1
line 2
line 3
.....
block2: line 1
line 2
line 3
......
block3: .....
要仅绘制block2,请使用命令
To plot only the block2, I use the command
plot 'file' u x1:x2 every :::2::2 w l
如何在plot
命令中仅收集每个块的第1行?
How to gather only line 1 of each block on the plot
command?
推荐答案
,因为数据点来自不同的块,它们之间用空行分隔.用空行分隔的数据点不会绘制为使用带线"连接.
my guess would be, because the datapoints are from different blocks they are separated by an empty line. And datapoints separated by an empty line are not plotted connected using "with lines".
尝试以下操作:将所需的数据写入新表,如下面的示例(gnuplot 5.2.5).
Try the following: write your desired data into a new table, like the example below (gnuplot 5.2.5).
### plot values of different blocks connected with lines
reset session
set colorsequence classic
$Data <<EOD
# block line xvalue yvalue
0 0 1 0
0 1 2 1
0 2 3 2
0 3 4 3
1 0 5 10
1 1 6 11
1 2 7 12
1 3 8 13
2 0 9 20
2 1 10 21
2 2 11 22
2 3 12 23
EOD
set table $Data2
plot $Data u 0:3:4 every ::0::0 with table
unset table
print $Data2
plot $Data u 3:4 w lp,\
$Data2 u 2:3 w lp
### end code
附加:如果要使用多个文件来执行此操作,请尝试以下操作 (到目前为止,最大的缺点是:未连接来自不同文件的点)
addition: if you want to do this with several files try the following below (little drawback so far: points from different files are not connected)
### plot every Nth line of all blocks of several systematic files
reset session
FileCount = 2 # number of files
Col1 = 1 # e.g. column of x value
Col2 = 2 # e.g. column of y value
N = 0 # N=0 is first line of each datablock, N=1 second line, etc...
set print $EveryNthLineFromAllBlocksOfAllFiles
do for [i=1:FileCount] {
FILE = sprintf("name_%d.dat",i)
set table $EveryNthLine
plot FILE u Col1:Col2 every ::N::N with table
unset table
print $EveryNthLine
}
set print
print $EveryNthLineFromAllBlocksOfAllFiles
plot $EveryNthLineFromAllBlocksOfAllFiles u 1:2 w lp
### end code
这篇关于用gnuplot绘制几个块数据的相同行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!