0
votes

I have a data file with the following structure

block1: line 1
        line 2
        line 3
       .....
block2: line 1
        line 2
        line 3
        ......
block3: .....

To plot only the block2, I use the command

plot 'file' u x1:x2 every :::2::2 w l

How to gather only line 1 of each block on the plot command?

1
Just as extra hint. When I am using the command plot 'file' u x1:x2 every ::3::3 w p I am getting an output. it plots line 3 of every block on a single plot? But If I change the option w p to w l nothing appears. Looks like the issue was also reported on stackoverflow - Many

1 Answers

1
votes

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".

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

enter image description here

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