J.Doe
J.Doe

Reputation: 109

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?

Upvotes: 2

Views: 181

Answers (1)

Tom Solid
Tom Solid

Reputation: 2344

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.

Upvotes: 2

Related Questions