Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

How to fill curve only up to a certain value, simultaneously with line gnuplot

I want to plot with filled curved only until when the value on the column one are less than zero. How should I do? Maybe plot two different line each time with different range?

My code is:

 p "data.txt"  ($1 <=0  ? $2 : 1/0) w filledcurves , '' ($1 <=0    ? $2 : 1/0) w filledcurves, 
 ...

But this way the value on the x-axis are wrong and the curve filled in a wrong strange way: enter image description here


In this other way the x-axis are right while the curve still filled up in a werid way:

plot 'data.txt' u 1:($1<=0?$2:1/0)

enter image description here

Are those a bug in gnuplot?

While I would be something like this but filled up only until zero: enter image description here

There is also a way to simultaneously plot with line, and select the line style?

question from:https://stackoverflow.com/questions/65924517/how-to-fill-curve-only-up-to-a-certain-value-simultaneously-with-line-gnuplot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are several problems:

1 - You should use using or u like:

plot "data.txt" u ($1 <=0  ? $2 : 1/0)

2 - In this form you plot the 2nd column (or nothing; depending on the 1st column) aganist the 0th column (which (nearly) equals to the line number). To examine this effect, try and see:

plot "data.txt" u 2

3 - ANSWER: the correct syntax is like:

plot 'data.txt' u ($1<=0?$1:1/0):2    

or

plot 'data.txt' u 1:($1<=0?$2:1/0) 

which depends on what do you want to plot actually. The difference between them that the first one sets the xrange of the plot up to 0 while the second one displays a wider xrange (up to x_max of your data). However, in your case, you could use both of them. (Or you can mix them.) Eg.:

plot 'data.txt' u 1:($1<=40?$2:1/0) w filledcurves y=0, '' u  1:($1>40?$2:1/0) w l lc 1

example

The problem with your plot was that using a 'naked' filledcurves with a 2 column data set, the default option is closed which threats the dataset as a closed polygon.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...