GNUPLOT: combining different series of points with vectors

I have a file with data in 2 columns X and Y. There are multiple blocks and they are separated by a blank line. I want to join the points (given by their x and y coordinates in the file) in each block using vectors. I am trying to use these functions:

prev_x = NaN
prev_y = NaN
dx(x) = (x_delta = x-prev_x, prev_x = ($0 > 0 ? x : 1/0), x_delta)
dy(y) = (y_delta = y-prev_y, prev_y = ($0 > 0 ? y : 1/0), y_delta)

      

which I took from Plotlines and vectors in gnuplot plots (first answer). The command to build will be plot for[i=0:5] 'Field_lines.txt' every :::i::i u (prev_x):(prev_y):(dx($1)):(dy($2)) with vectors

. The way out enter image description here, and the problem is that point (0,0) is included even though it is not in the file. I don't think I understand what the functions do dx

and dy

exactly and how they are used with the option using (prev_x):(prev_y):(dx($1)):(dy($2))

, so explaining this will help me a lot to try to fix this. This is the file:

#1
0   5   
0   4   
0   3   
0.4 2   
0.8 1   
0.8 1   

#2
2   5
2   4
2   3
2   2
2   1
2   0

#3
4   5
4.2 4
4.5 3
4.6 2
4.7 1
4.7 0

#4
7   5
7.2 4
7.5 3
7.9 2
7.9 1
7.9 0

#5 
9   5
9   4
9.2 3
9.5 2
9.5 1
9.5 0

#6
11  7
12  6
13  5
13.3    4
13.5    3
13.5    2
13.6    1
14  0

      

Thank!

+3


source to share


1 answer


I'm not really sure what the real problem is, but I think you cannot rely on columns in an expression using

to evaluate from left to right, and your validation is $0 > 0

in dx

and dy

some is too late in my opinion.

I usually put all assignments and conditionals in the first column and this works great in your case too:

set offsets 1,1,1,1
unset key
prev_x = prev_y = 1

plot for [i=0:5] 'Field_lines.txt' every :::i::i \
    u (x_delta = prev_x-$1, prev_x=$1, y_delta=prev_y-$2, prev_y=$2, ($0 == 0 ? 1/0 : prev_x)):(prev_y):(x_delta):(y_delta) with vectors backhead

      



Also, to draw a vector from the jth line to a point on the next line, you must invert the definition x_delta

and use backhead

to draw the vectors in the right direction

enter image description here

+1


source







All Articles