Gnuplot: connecting two data with line at a certain point

别来无恙 提交于 2019-12-24 00:30:02

问题


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?


回答1:


Prue Gnuplot soulution:

plot 'sheme.dat' u 1:($1<=5?$2:$3) w l

If you want, you can refine the condition to handle cases x<1 and x>10...

OR

If you want to plot lines 1-5 with y1 and 6-10 with y2, use column zero:

plot 'sheme.dat' u 1:($0<=4?$2:$3) w l




回答2:


AFAIK there is no solution with pure gnuplot, but you can do almost everything by invoking an external unix tool. If you remove the first line (header) in your data file (henceforth data.txt), this should work:

plot "<awk '{if (NR<=5) print $1,$2; else print $1,$3}' data.txt"  w lp



来源:https://stackoverflow.com/questions/37835244/gnuplot-connecting-two-data-with-line-at-a-certain-point

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!