2
votes

I am having some difficulty generating a plot of a data set that is oscillating between negative and positive values (line a sin or cos). My goal is to fill the area under the curve with alternating colour: negative region with blue and positive with red. To be more precise I want to fill the area between the curve and the x axis. So far i managed to plot the curve with alternating colours (blue for negative, red for positive) using:

set palette model RGB defined ( 0 'red', 1 'blue' )
unset colorbox
plot 'data.set' u 1:2:( $2 < 0.0 ? 1 : 0 ) w lines lt 1 lw 4 palette

Unfortunately if I replace w lines with filledcurves I don't get an alternate fill. How can one accomplish this?

Cheers

1

1 Answers

3
votes

If I understood the question correctly, you can try this:

plot '+' using 1:(0):(sin($1)) w filledc below, \
     '+' using 1:(0):(sin($1)) w filledc above

which is telling gnuplot to fill the area between two curves (sin(x) and 0), using the above and below positions. There is another solution as well:

plot '+' using 1:(sin($1) > 0 ? sin($1):0) w filledcurves y1, \
     '+' using 1:(sin($1) < 0 ? sin($1):0) w filledcurves y2

and the result would be:

output

The important part refers to the options part of filledcurves. See more details here and here.