Reputation: 109
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:
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)
Are those a bug in gnuplot?
While I would be something like this but filled up only until zero:
There is also a way to simultaneously plot with line, and select the line style?
Upvotes: 2
Views: 181
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
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