Tom Solid
Tom Solid

Reputation: 2344

Gnuplot: connecting two data with line at a certain point from different data files

This question is an extension of a previously answered one.

I want a graph using gnuplot with two data in mixed scheme. This is a data consisting of 3 columns:

#x   y1   y2
1   0    1    
2   0    1    
3   0    1    
4   0    1    
5   0    1    
6   0    1    
7   0    1    
8   0    1    
9   0.1  1.2
10  0.1  1.23

What I want is that one line draws without seam. e.g.

From x=1 to x=5, use y1 value, then from x=6 to x=10 use y2 value.

And, all the points are connected with one single line. Does any body know how to make it with simple gnuplot command?

One more related question is there. If the data in 3rd column is separated to other file, say sheme2.dat, how can i draw a same graph with pure gnuplot commands?

Upvotes: 1

Views: 811

Answers (2)

Vinicius Placco
Vinicius Placco

Reputation: 1731

For a file with columns 1/2 and a second file with column 3 you can use paste as well:

plot "<paste -d ' ' data1.dat data2.dat" using 1:($1<=5?$2:$3) with lines

With the -d ' ' meaning that data1.dat and data2.dat will be separated by a single space.

For three columns in one file (as answered before)

plot "data.dat" using 1:($1<=5?$2:$3) with lines

Upvotes: 0

Tom Solid
Tom Solid

Reputation: 2344

If you absolutely want to use pure Gnuplot you can cheat a little with variables(, but I suggest you to rethink the problem):

set term unknown

plot 'sheme.dat' u 1:2 every ::::4
x0=GPVAL_DATA_X_MAX
y0=GPVAL_DATA_Y_MAX

plot 'sheme2.dat' u 1:2 every ::5
x1=GPVAL_DATA_X_MIN
y1=GPVAL_DATA_Y_MIN

set term wxt
# or png or qt or...

set arrow 1 from x0,y0 to x1,y1 nohead lc 1
plot 'sheme.dat' u 1:2 every ::::4 w l lc 1
replot 'sheme2.dat' u 1:2 every ::5 w l lc 1

This is a tricky way to connect the last and first data points with an arrow, but the conditions of this problem are so specific.

enter image description here

Upvotes: 2

Related Questions